Skip to main content

glam/f64/
dvec4.rs

1// Generated from vec.rs.tera template. Edit the template, not the generated file.
2
3#[cfg(not(feature = "scalar-math"))]
4use crate::BVec4A;
5use crate::{BVec4, DVec2, DVec3, f64::math};
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/// Creates a 4-dimensional vector.
23#[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/// A 4-dimensional vector.
30#[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    /// All zeroes.
48    pub const ZERO: Self = Self::splat(0.0);
49
50    /// All ones.
51    pub const ONE: Self = Self::splat(1.0);
52
53    /// All negative ones.
54    pub const NEG_ONE: Self = Self::splat(-1.0);
55
56    /// All `f64::MIN`.
57    pub const MIN: Self = Self::splat(f64::MIN);
58
59    /// All `f64::MAX`.
60    pub const MAX: Self = Self::splat(f64::MAX);
61
62    /// All `f64::NAN`.
63    pub const NAN: Self = Self::splat(f64::NAN);
64
65    /// All `f64::INFINITY`.
66    pub const INFINITY: Self = Self::splat(f64::INFINITY);
67
68    /// All `f64::NEG_INFINITY`.
69    pub const NEG_INFINITY: Self = Self::splat(f64::NEG_INFINITY);
70
71    /// A unit vector pointing along the positive X axis.
72    pub const X: Self = Self::new(1.0, 0.0, 0.0, 0.0);
73
74    /// A unit vector pointing along the positive Y axis.
75    pub const Y: Self = Self::new(0.0, 1.0, 0.0, 0.0);
76
77    /// A unit vector pointing along the positive Z axis.
78    pub const Z: Self = Self::new(0.0, 0.0, 1.0, 0.0);
79
80    /// A unit vector pointing along the positive W axis.
81    pub const W: Self = Self::new(0.0, 0.0, 0.0, 1.0);
82
83    /// A unit vector pointing along the negative X axis.
84    pub const NEG_X: Self = Self::new(-1.0, 0.0, 0.0, 0.0);
85
86    /// A unit vector pointing along the negative Y axis.
87    pub const NEG_Y: Self = Self::new(0.0, -1.0, 0.0, 0.0);
88
89    /// A unit vector pointing along the negative Z axis.
90    pub const NEG_Z: Self = Self::new(0.0, 0.0, -1.0, 0.0);
91
92    /// A unit vector pointing along the negative W axis.
93    pub const NEG_W: Self = Self::new(0.0, 0.0, 0.0, -1.0);
94
95    /// The unit axes.
96    pub const AXES: [Self; 4] = [Self::X, Self::Y, Self::Z, Self::W];
97
98    /// DVec4 uses Rust Portable SIMD
99    pub const USES_CORE_SIMD: bool = false;
100    /// DVec4 uses Arm NEON
101    pub const USES_NEON: bool = false;
102    /// DVec4 uses scalar math
103    pub const USES_SCALAR_MATH: bool = true;
104    /// DVec4 uses Intel SSE2
105    pub const USES_SSE2: bool = false;
106    /// DVec4 uses WebAssembly 128-bit SIMD
107    pub const USES_WASM_SIMD: bool = false;
108
109    /// Creates a new vector.
110    #[inline(always)]
111    #[must_use]
112    pub const fn new(x: f64, y: f64, z: f64, w: f64) -> Self {
113        Self { x, y, z, w }
114    }
115
116    /// Creates a vector with all elements set to `v`.
117    #[inline]
118    #[must_use]
119    pub const fn splat(v: f64) -> Self {
120        Self::new(v, v, v, v)
121    }
122
123    /// Returns a vector containing each element of `self` modified by a mapping function `f`.
124    #[inline]
125    #[must_use]
126    pub fn map<F>(self, mut f: F) -> Self
127    where
128        F: FnMut(f64) -> f64,
129    {
130        Self::new(f(self.x), f(self.y), f(self.z), f(self.w))
131    }
132
133    /// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use
134    /// for each element of `self`.
135    ///
136    /// A true element in the mask uses the corresponding element from `if_true`, and false
137    /// uses the element from `if_false`.
138    #[inline]
139    #[must_use]
140    pub fn select(mask: BVec4, if_true: Self, if_false: Self) -> Self {
141        Self::new(
142            if mask.test(0) { if_true.x } else { if_false.x },
143            if mask.test(1) { if_true.y } else { if_false.y },
144            if mask.test(2) { if_true.z } else { if_false.z },
145            if mask.test(3) { if_true.w } else { if_false.w },
146        )
147    }
148
149    /// Creates a new vector from an array.
150    #[inline]
151    #[must_use]
152    pub const fn from_array(a: [f64; 4]) -> Self {
153        Self::new(a[0], a[1], a[2], a[3])
154    }
155
156    /// Converts `self` to `[x, y, z, w]`
157    #[inline]
158    #[must_use]
159    pub const fn to_array(&self) -> [f64; 4] {
160        [self.x, self.y, self.z, self.w]
161    }
162
163    /// Creates a vector from the first 4 values in `slice`.
164    ///
165    /// # Panics
166    ///
167    /// Panics if `slice` is less than 4 elements long.
168    #[inline]
169    #[must_use]
170    #[track_caller]
171    pub const fn from_slice(slice: &[f64]) -> Self {
172        assert!(slice.len() >= 4);
173        Self::new(slice[0], slice[1], slice[2], slice[3])
174    }
175
176    /// Writes the elements of `self` to the first 4 elements in `slice`.
177    ///
178    /// # Panics
179    ///
180    /// Panics if `slice` is less than 4 elements long.
181    #[inline]
182    #[track_caller]
183    pub fn write_to_slice(self, slice: &mut [f64]) {
184        slice[..4].copy_from_slice(&self.to_array());
185    }
186
187    /// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`.
188    ///
189    /// Truncation to [`DVec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()].
190    #[inline]
191    #[must_use]
192    pub fn truncate(self) -> DVec3 {
193        use crate::swizzles::Vec4Swizzles;
194        self.xyz()
195    }
196
197    /// Projects a homogeneous coordinate to 3D space by performing perspective divide.
198    ///
199    /// # Panics
200    ///
201    /// Will panic if `self.w` is `0` when `glam_assert` is enabled.
202    #[inline]
203    #[must_use]
204    #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
205    pub fn project(self) -> DVec3 {
206        DVec3::from_homogeneous(self)
207    }
208
209    /// Creates a 4D vector from `self` with the given value of `x`.
210    #[inline]
211    #[must_use]
212    pub fn with_x(mut self, x: f64) -> Self {
213        self.x = x;
214        self
215    }
216
217    /// Creates a 4D vector from `self` with the given value of `y`.
218    #[inline]
219    #[must_use]
220    pub fn with_y(mut self, y: f64) -> Self {
221        self.y = y;
222        self
223    }
224
225    /// Creates a 4D vector from `self` with the given value of `z`.
226    #[inline]
227    #[must_use]
228    pub fn with_z(mut self, z: f64) -> Self {
229        self.z = z;
230        self
231    }
232
233    /// Creates a 4D vector from `self` with the given value of `w`.
234    #[inline]
235    #[must_use]
236    pub fn with_w(mut self, w: f64) -> Self {
237        self.w = w;
238        self
239    }
240
241    /// Computes the dot product of `self` and `rhs`.
242    #[inline]
243    #[must_use]
244    pub fn dot(self, rhs: Self) -> f64 {
245        (self.x * rhs.x) + (self.y * rhs.y) + (self.z * rhs.z) + (self.w * rhs.w)
246    }
247
248    /// Returns a vector where every component is the dot product of `self` and `rhs`.
249    #[inline]
250    #[must_use]
251    pub fn dot_into_vec(self, rhs: Self) -> Self {
252        Self::splat(self.dot(rhs))
253    }
254
255    /// Returns a vector containing the minimum values for each element of `self` and `rhs`.
256    ///
257    /// In other words this computes `[min(x, rhs.x), min(self.y, rhs.y), ..]`.
258    ///
259    /// `-0.0` and `+0.0` compare equal, so `rhs` is returned.
260    ///
261    /// NaN propagation does not follow IEEE 754-2008 semantics for minNum.
262    #[inline]
263    #[must_use]
264    pub fn min(self, rhs: Self) -> Self {
265        Self::new(
266            if self.x < rhs.x { self.x } else { rhs.x },
267            if self.y < rhs.y { self.y } else { rhs.y },
268            if self.z < rhs.z { self.z } else { rhs.z },
269            if self.w < rhs.w { self.w } else { rhs.w },
270        )
271    }
272
273    /// Returns a vector containing the maximum values for each element of `self` and `rhs`.
274    ///
275    /// In other words this computes `[max(self.x, rhs.x), max(self.y, rhs.y), ..]`.
276    ///
277    /// `-0.0` and `+0.0` compare equal, so `rhs` is returned.
278    ///
279    /// NaN propagation does not follow IEEE 754-2008 semantics for maxNum.
280    #[inline]
281    #[must_use]
282    pub fn max(self, rhs: Self) -> Self {
283        Self::new(
284            if self.x > rhs.x { self.x } else { rhs.x },
285            if self.y > rhs.y { self.y } else { rhs.y },
286            if self.z > rhs.z { self.z } else { rhs.z },
287            if self.w > rhs.w { self.w } else { rhs.w },
288        )
289    }
290
291    /// Component-wise clamping of values, similar to [`f64::clamp`].
292    ///
293    /// Each element in `min` must be less-or-equal to the corresponding element in `max`.
294    ///
295    /// NaN propagation does not follow IEEE 754-2008 semantics.
296    ///
297    /// # Panics
298    ///
299    /// Will panic if `min` is greater than `max` when `glam_assert` is enabled.
300    #[inline]
301    #[must_use]
302    #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
303    pub fn clamp(self, min: Self, max: Self) -> Self {
304        glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
305        self.max(min).min(max)
306    }
307
308    /// Returns the horizontal minimum of `self`.
309    ///
310    /// In other words this computes `min(x, y, ..)`.
311    ///
312    /// NaN propagation does not follow IEEE 754-2008 semantics for minNum.
313    #[inline]
314    #[must_use]
315    pub fn min_element(self) -> f64 {
316        let min = |a, b| if a < b { a } else { b };
317        min(min(self.x, self.y), min(self.z, self.w))
318    }
319
320    /// Returns the horizontal maximum of `self`.
321    ///
322    /// In other words this computes `max(x, y, ..)`.
323    ///
324    /// NaN propagation does not follow IEEE 754-2008 semantics for maxNum.
325    #[inline]
326    #[must_use]
327    pub fn max_element(self) -> f64 {
328        let max = |a, b| if a > b { a } else { b };
329        max(max(self.x, self.y), max(self.z, self.w))
330    }
331
332    /// Returns the index of the first minimum element of `self`.
333    #[doc(alias = "argmin")]
334    #[inline]
335    #[must_use]
336    pub fn min_position(self) -> usize {
337        let mut min = self.x;
338        let mut index = 0;
339        if self.y < min {
340            min = self.y;
341            index = 1;
342        }
343        if self.z < min {
344            min = self.z;
345            index = 2;
346        }
347        if self.w < min {
348            index = 3;
349        }
350        index
351    }
352
353    /// Returns the index of the first maximum element of `self`.
354    #[doc(alias = "argmax")]
355    #[inline]
356    #[must_use]
357    pub fn max_position(self) -> usize {
358        let mut max = self.x;
359        let mut index = 0;
360        if self.y > max {
361            max = self.y;
362            index = 1;
363        }
364        if self.z > max {
365            max = self.z;
366            index = 2;
367        }
368        if self.w > max {
369            index = 3;
370        }
371        index
372    }
373
374    /// Returns the sum of all elements of `self`.
375    ///
376    /// In other words, this computes `self.x + self.y + ..`.
377    #[inline]
378    #[must_use]
379    pub fn element_sum(self) -> f64 {
380        self.x + self.y + self.z + self.w
381    }
382
383    /// Returns the product of all elements of `self`.
384    ///
385    /// In other words, this computes `self.x * self.y * ..`.
386    #[inline]
387    #[must_use]
388    pub fn element_product(self) -> f64 {
389        self.x * self.y * self.z * self.w
390    }
391
392    /// Returns a vector mask containing the result of a `==` comparison for each element of
393    /// `self` and `rhs`.
394    ///
395    /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all
396    /// elements.
397    #[inline]
398    #[must_use]
399    pub fn cmpeq(self, rhs: Self) -> BVec4 {
400        BVec4::new(
401            self.x.eq(&rhs.x),
402            self.y.eq(&rhs.y),
403            self.z.eq(&rhs.z),
404            self.w.eq(&rhs.w),
405        )
406    }
407
408    /// Returns a vector mask containing the result of a `!=` comparison for each element of
409    /// `self` and `rhs`.
410    ///
411    /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all
412    /// elements.
413    #[inline]
414    #[must_use]
415    pub fn cmpne(self, rhs: Self) -> BVec4 {
416        BVec4::new(
417            self.x.ne(&rhs.x),
418            self.y.ne(&rhs.y),
419            self.z.ne(&rhs.z),
420            self.w.ne(&rhs.w),
421        )
422    }
423
424    /// Returns a vector mask containing the result of a `>=` comparison for each element of
425    /// `self` and `rhs`.
426    ///
427    /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all
428    /// elements.
429    #[inline]
430    #[must_use]
431    pub fn cmpge(self, rhs: Self) -> BVec4 {
432        BVec4::new(
433            self.x.ge(&rhs.x),
434            self.y.ge(&rhs.y),
435            self.z.ge(&rhs.z),
436            self.w.ge(&rhs.w),
437        )
438    }
439
440    /// Returns a vector mask containing the result of a `>` comparison for each element of
441    /// `self` and `rhs`.
442    ///
443    /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all
444    /// elements.
445    #[inline]
446    #[must_use]
447    pub fn cmpgt(self, rhs: Self) -> BVec4 {
448        BVec4::new(
449            self.x.gt(&rhs.x),
450            self.y.gt(&rhs.y),
451            self.z.gt(&rhs.z),
452            self.w.gt(&rhs.w),
453        )
454    }
455
456    /// Returns a vector mask containing the result of a `<=` comparison for each element of
457    /// `self` and `rhs`.
458    ///
459    /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all
460    /// elements.
461    #[inline]
462    #[must_use]
463    pub fn cmple(self, rhs: Self) -> BVec4 {
464        BVec4::new(
465            self.x.le(&rhs.x),
466            self.y.le(&rhs.y),
467            self.z.le(&rhs.z),
468            self.w.le(&rhs.w),
469        )
470    }
471
472    /// Returns a vector mask containing the result of a `<` comparison for each element of
473    /// `self` and `rhs`.
474    ///
475    /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all
476    /// elements.
477    #[inline]
478    #[must_use]
479    pub fn cmplt(self, rhs: Self) -> BVec4 {
480        BVec4::new(
481            self.x.lt(&rhs.x),
482            self.y.lt(&rhs.y),
483            self.z.lt(&rhs.z),
484            self.w.lt(&rhs.w),
485        )
486    }
487
488    /// Returns a vector containing the absolute value of each element of `self`.
489    #[inline]
490    #[must_use]
491    pub fn abs(self) -> Self {
492        Self::new(self.x.abs(), self.y.abs(), self.z.abs(), self.w.abs())
493    }
494
495    /// Returns a vector with elements representing the sign of `self`.
496    ///
497    /// - `1.0` if the number is positive, `+0.0` or `INFINITY`
498    /// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY`
499    /// - `NAN` if the number is `NAN`
500    #[inline]
501    #[must_use]
502    pub fn signum(self) -> Self {
503        Self::new(
504            self.x.signum(),
505            self.y.signum(),
506            self.z.signum(),
507            self.w.signum(),
508        )
509    }
510
511    /// Returns a vector with signs of `rhs` and the magnitudes of `self`.
512    #[inline]
513    #[must_use]
514    pub fn copysign(self, rhs: Self) -> Self {
515        Self::new(
516            self.x.copysign(rhs.x),
517            self.y.copysign(rhs.y),
518            self.z.copysign(rhs.z),
519            self.w.copysign(rhs.w),
520        )
521    }
522
523    /// Returns a bitmask with the lowest 4 bits set to the sign bits from the elements of `self`.
524    ///
525    /// A negative element results in a `1` bit and a positive element in a `0` bit.  Element `x` goes
526    /// into the first lowest bit, element `y` into the second, etc.
527    ///
528    /// An element is negative if it has a negative sign, including -0.0, NaNs with negative sign
529    /// bit and negative infinity.
530    #[inline]
531    #[must_use]
532    pub fn is_negative_bitmask(self) -> u32 {
533        (self.x.is_sign_negative() as u32)
534            | ((self.y.is_sign_negative() as u32) << 1)
535            | ((self.z.is_sign_negative() as u32) << 2)
536            | ((self.w.is_sign_negative() as u32) << 3)
537    }
538
539    /// Returns a mask indicating which components are negative.
540    ///
541    /// An element is negative if it has a negative sign, including -0.0, NaNs with negative sign
542    /// bit and negative infinity.
543    #[inline]
544    #[must_use]
545    pub fn is_negative_mask(self) -> BVec4 {
546        BVec4::new(
547            self.x.is_sign_negative(),
548            self.y.is_sign_negative(),
549            self.z.is_sign_negative(),
550            self.w.is_sign_negative(),
551        )
552    }
553
554    /// Returns `true` if, and only if, all elements are finite.  If any element is either
555    /// `NaN`, positive or negative infinity, this will return `false`.
556    #[inline]
557    #[must_use]
558    pub fn is_finite(self) -> bool {
559        self.x.is_finite() && self.y.is_finite() && self.z.is_finite() && self.w.is_finite()
560    }
561
562    /// Performs `is_finite` on each element of self, returning a vector mask of the results.
563    ///
564    /// In other words, this computes `[x.is_finite(), y.is_finite(), ...]`.
565    #[inline]
566    #[must_use]
567    pub fn is_finite_mask(self) -> BVec4 {
568        BVec4::new(
569            self.x.is_finite(),
570            self.y.is_finite(),
571            self.z.is_finite(),
572            self.w.is_finite(),
573        )
574    }
575
576    /// Returns `true` if any elements are `NaN`.
577    #[inline]
578    #[must_use]
579    pub fn is_nan(self) -> bool {
580        self.x.is_nan() || self.y.is_nan() || self.z.is_nan() || self.w.is_nan()
581    }
582
583    /// Performs `is_nan` on each element of self, returning a vector mask of the results.
584    ///
585    /// In other words, this computes `[x.is_nan(), y.is_nan(), ...]`.
586    #[inline]
587    #[must_use]
588    pub fn is_nan_mask(self) -> BVec4 {
589        BVec4::new(
590            self.x.is_nan(),
591            self.y.is_nan(),
592            self.z.is_nan(),
593            self.w.is_nan(),
594        )
595    }
596
597    /// Computes the length of `self`.
598    #[doc(alias = "magnitude")]
599    #[inline]
600    #[must_use]
601    pub fn length(self) -> f64 {
602        math::sqrt(self.dot(self))
603    }
604
605    /// Returns `true` if the vector is not the zero vector (also rejects NaN).
606    #[allow(dead_code)]
607    fn is_non_zero(self) -> bool {
608        self.length_squared() > 0.0
609    }
610
611    /// Computes the squared length of `self`.
612    ///
613    /// This is faster than `length()` as it avoids a square root operation.
614    #[doc(alias = "magnitude2")]
615    #[inline]
616    #[must_use]
617    pub fn length_squared(self) -> f64 {
618        self.dot(self)
619    }
620
621    /// Computes `1.0 / length()`.
622    ///
623    /// For valid results, `self` must _not_ be of length zero.
624    #[inline]
625    #[must_use]
626    pub fn length_recip(self) -> f64 {
627        1.0 / self.length()
628    }
629
630    /// Computes the Euclidean distance between two points in space.
631    #[inline]
632    #[must_use]
633    pub fn distance(self, rhs: Self) -> f64 {
634        (self - rhs).length()
635    }
636
637    /// Compute the squared euclidean distance between two points in space.
638    #[inline]
639    #[must_use]
640    pub fn distance_squared(self, rhs: Self) -> f64 {
641        (self - rhs).length_squared()
642    }
643
644    /// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`.
645    #[inline]
646    #[must_use]
647    pub fn div_euclid(self, rhs: Self) -> Self {
648        Self::new(
649            math::div_euclid(self.x, rhs.x),
650            math::div_euclid(self.y, rhs.y),
651            math::div_euclid(self.z, rhs.z),
652            math::div_euclid(self.w, rhs.w),
653        )
654    }
655
656    /// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`.
657    ///
658    /// [Euclidean division]: f64::rem_euclid
659    #[inline]
660    #[must_use]
661    pub fn rem_euclid(self, rhs: Self) -> Self {
662        Self::new(
663            math::rem_euclid(self.x, rhs.x),
664            math::rem_euclid(self.y, rhs.y),
665            math::rem_euclid(self.z, rhs.z),
666            math::rem_euclid(self.w, rhs.w),
667        )
668    }
669
670    /// Returns `self` normalized to length 1.0.
671    ///
672    /// For valid results, `self` must be finite and _not_ of length zero, nor very close to zero.
673    ///
674    /// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`].
675    ///
676    /// # Panics
677    ///
678    /// Will panic if the resulting normalized vector is not finite when `glam_assert` is enabled.
679    #[inline]
680    #[must_use]
681    #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
682    pub fn normalize(self) -> Self {
683        #[allow(clippy::let_and_return)]
684        let normalized = self.mul(self.length_recip());
685        glam_assert!(normalized.is_finite());
686        normalized
687    }
688
689    /// Returns `self` normalized to length 1.0 if possible, else returns `None`.
690    ///
691    /// In particular, if the input is zero (or very close to zero), or non-finite,
692    /// the result of this operation will be `None`.
693    ///
694    /// See also [`Self::normalize_or_zero()`].
695    #[inline]
696    #[must_use]
697    pub fn try_normalize(self) -> Option<Self> {
698        let rcp = self.length_recip();
699        if rcp.is_finite() && rcp > 0.0 {
700            Some(self * rcp)
701        } else {
702            None
703        }
704    }
705
706    /// Returns `self` normalized to length 1.0 if possible, else returns a
707    /// fallback value.
708    ///
709    /// In particular, if the input is zero (or very close to zero), or non-finite,
710    /// the result of this operation will be the fallback value.
711    ///
712    /// See also [`Self::try_normalize()`].
713    #[inline]
714    #[must_use]
715    pub fn normalize_or(self, fallback: Self) -> Self {
716        let rcp = self.length_recip();
717        if rcp.is_finite() && rcp > 0.0 {
718            self * rcp
719        } else {
720            fallback
721        }
722    }
723
724    /// Returns `self` normalized to length 1.0 if possible, else returns zero.
725    ///
726    /// In particular, if the input is zero (or very close to zero), or non-finite,
727    /// the result of this operation will be zero.
728    ///
729    /// See also [`Self::try_normalize()`].
730    #[inline]
731    #[must_use]
732    pub fn normalize_or_zero(self) -> Self {
733        self.normalize_or(Self::ZERO)
734    }
735
736    /// Returns `self` normalized to length 1.0 and the length of `self`.
737    ///
738    /// If `self` is zero length then `(Self::X, 0.0)` is returned.
739    #[inline]
740    #[must_use]
741    pub fn normalize_and_length(self) -> (Self, f64) {
742        let length = self.length();
743        let rcp = 1.0 / length;
744        if rcp.is_finite() && rcp > 0.0 {
745            (self * rcp, length)
746        } else {
747            (Self::X, 0.0)
748        }
749    }
750
751    /// Returns whether `self` is length `1.0` or not.
752    ///
753    /// Uses a precision threshold of approximately `1e-4`.
754    #[inline]
755    #[must_use]
756    pub fn is_normalized(self) -> bool {
757        (self.length_squared() - 1.0).abs() <= 2e-4
758    }
759
760    /// Returns the vector projection of `self` onto `rhs`.
761    ///
762    /// `rhs` must be of non-zero length.
763    ///
764    /// # Panics
765    ///
766    /// Will panic if `rhs` is zero length when `glam_assert` is enabled.
767    #[inline]
768    #[must_use]
769    #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
770    pub fn project_onto(self, rhs: Self) -> Self {
771        let rhs_len_sq = rhs.dot(rhs);
772        glam_assert!(rhs_len_sq != 0.0);
773        rhs * (self.dot(rhs) / rhs_len_sq)
774    }
775
776    /// Returns the vector rejection of `self` from `rhs`.
777    ///
778    /// The vector rejection is the vector perpendicular to the projection of `self` onto
779    /// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`.
780    ///
781    /// `rhs` must be of non-zero length.
782    ///
783    /// # Panics
784    ///
785    /// Will panic if `rhs` has a length of zero when `glam_assert` is enabled.
786    #[doc(alias("plane"))]
787    #[inline]
788    #[must_use]
789    #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
790    pub fn reject_from(self, rhs: Self) -> Self {
791        self - self.project_onto(rhs)
792    }
793
794    /// Returns the vector projection of `self` onto `rhs`.
795    ///
796    /// `rhs` must be normalized.
797    ///
798    /// # Panics
799    ///
800    /// Will panic if `rhs` is not normalized when `glam_assert` is enabled.
801    #[inline]
802    #[must_use]
803    #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
804    pub fn project_onto_normalized(self, rhs: Self) -> Self {
805        glam_assert!(rhs.is_normalized());
806        rhs * self.dot(rhs)
807    }
808
809    /// Returns the vector rejection of `self` from `rhs`.
810    ///
811    /// The vector rejection is the vector perpendicular to the projection of `self` onto
812    /// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`.
813    ///
814    /// `rhs` must be normalized.
815    ///
816    /// # Panics
817    ///
818    /// Will panic if `rhs` is not normalized when `glam_assert` is enabled.
819    #[doc(alias("plane"))]
820    #[inline]
821    #[must_use]
822    #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
823    pub fn reject_from_normalized(self, rhs: Self) -> Self {
824        self - self.project_onto_normalized(rhs)
825    }
826
827    /// Returns a vector containing the nearest integer to a number for each element of `self`.
828    /// Round half-way cases away from 0.0.
829    #[inline]
830    #[must_use]
831    pub fn round(self) -> Self {
832        Self::new(
833            math::round(self.x),
834            math::round(self.y),
835            math::round(self.z),
836            math::round(self.w),
837        )
838    }
839
840    /// Returns a vector containing the largest integer less than or equal to a number for each
841    /// element of `self`.
842    #[inline]
843    #[must_use]
844    pub fn floor(self) -> Self {
845        Self::new(
846            math::floor(self.x),
847            math::floor(self.y),
848            math::floor(self.z),
849            math::floor(self.w),
850        )
851    }
852
853    /// Returns a vector containing the smallest integer greater than or equal to a number for
854    /// each element of `self`.
855    #[inline]
856    #[must_use]
857    pub fn ceil(self) -> Self {
858        Self::new(
859            math::ceil(self.x),
860            math::ceil(self.y),
861            math::ceil(self.z),
862            math::ceil(self.w),
863        )
864    }
865
866    /// Returns a vector containing the integer part each element of `self`. This means numbers are
867    /// always truncated towards zero.
868    #[inline]
869    #[must_use]
870    pub fn trunc(self) -> Self {
871        Self::new(
872            math::trunc(self.x),
873            math::trunc(self.y),
874            math::trunc(self.z),
875            math::trunc(self.w),
876        )
877    }
878
879    /// Returns a vector containing `0.0` if `rhs < self` and 1.0 otherwise.
880    ///
881    /// Similar to glsl's step(edge, x), which translates into edge.step(x)
882    #[inline]
883    #[must_use]
884    pub fn step(self, rhs: Self) -> Self {
885        Self::select(rhs.cmplt(self), Self::ZERO, Self::ONE)
886    }
887
888    /// Performs Hermite interpolation between `0.0` and `1.0` using `x` normalized to `[edge0, edge1]`.
889    ///
890    /// This is equivalent to `t * t * (3.0 - 2.0 * t)`, where `t` is clamped to `[0.0, 1.0]`.
891    /// Results are undefined if any element of `edge0` is greater than or equal to the corresponding
892    /// element of `edge1`.
893    ///
894    /// # Panics
895    ///
896    /// Will panic if any element of `edge0` is greater than or equal to the corresponding element
897    /// of `edge1`, when `glam_assert` is enabled.
898    #[inline]
899    #[must_use]
900    #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
901    pub fn smoothstep(self, edge0: Self, edge1: Self) -> Self {
902        glam_assert!(edge0.cmplt(edge1).all());
903        let t = ((self - edge0) / (edge1 - edge0)).saturate();
904        t * t * (Self::splat(3.0) - Self::splat(2.0) * t)
905    }
906
907    /// Returns a vector containing all elements of `self` clamped to the range of `[0, 1]`.
908    #[inline]
909    #[must_use]
910    pub fn saturate(self) -> Self {
911        self.clamp(Self::ZERO, Self::ONE)
912    }
913
914    /// Returns a vector containing the fractional part of the vector as `self - self.trunc()`.
915    ///
916    /// Note that this differs from the GLSL implementation of `fract` which returns
917    /// `self - self.floor()`.
918    ///
919    /// Note that this is fast but not precise for large numbers.
920    #[inline]
921    #[must_use]
922    pub fn fract(self) -> Self {
923        self - self.trunc()
924    }
925
926    /// Returns a vector containing the fractional part of the vector as `self - self.floor()`.
927    ///
928    /// Note that this differs from the Rust implementation of `fract` which returns
929    /// `self - self.trunc()`.
930    ///
931    /// Note that this is fast but not precise for large numbers.
932    #[inline]
933    #[must_use]
934    pub fn fract_gl(self) -> Self {
935        self - self.floor()
936    }
937
938    /// Returns a vector containing `e^self` (the exponential function) for each element of
939    /// `self`.
940    #[inline]
941    #[must_use]
942    pub fn exp(self) -> Self {
943        Self::new(
944            math::exp(self.x),
945            math::exp(self.y),
946            math::exp(self.z),
947            math::exp(self.w),
948        )
949    }
950
951    /// Returns a vector containing `2^self` for each element of `self`.
952    #[inline]
953    #[must_use]
954    pub fn exp2(self) -> Self {
955        Self::new(
956            math::exp2(self.x),
957            math::exp2(self.y),
958            math::exp2(self.z),
959            math::exp2(self.w),
960        )
961    }
962
963    /// Returns a vector containing the natural logarithm for each element of `self`.
964    /// This returns NaN when the element is negative and negative infinity when the element is zero.
965    #[inline]
966    #[must_use]
967    pub fn ln(self) -> Self {
968        Self::new(
969            math::ln(self.x),
970            math::ln(self.y),
971            math::ln(self.z),
972            math::ln(self.w),
973        )
974    }
975
976    /// Returns a vector containing the base 2 logarithm for each element of `self`.
977    /// This returns NaN when the element is negative and negative infinity when the element is zero.
978    #[inline]
979    #[must_use]
980    pub fn log2(self) -> Self {
981        Self::new(
982            math::log2(self.x),
983            math::log2(self.y),
984            math::log2(self.z),
985            math::log2(self.w),
986        )
987    }
988
989    /// Returns a vector containing each element of `self` raised to the power of `n`.
990    #[inline]
991    #[must_use]
992    pub fn powf(self, n: f64) -> Self {
993        Self::new(
994            math::powf(self.x, n),
995            math::powf(self.y, n),
996            math::powf(self.z, n),
997            math::powf(self.w, n),
998        )
999    }
1000
1001    /// Returns a vector containing the square root for each element of `self`.
1002    /// This returns NaN when the element is negative.
1003    #[inline]
1004    #[must_use]
1005    pub fn sqrt(self) -> Self {
1006        Self::new(
1007            math::sqrt(self.x),
1008            math::sqrt(self.y),
1009            math::sqrt(self.z),
1010            math::sqrt(self.w),
1011        )
1012    }
1013
1014    /// Returns a vector containing the cosine for each element of `self`.
1015    #[inline]
1016    #[must_use]
1017    pub fn cos(self) -> Self {
1018        Self::new(
1019            math::cos(self.x),
1020            math::cos(self.y),
1021            math::cos(self.z),
1022            math::cos(self.w),
1023        )
1024    }
1025
1026    /// Returns a vector containing the sine for each element of `self`.
1027    #[inline]
1028    #[must_use]
1029    pub fn sin(self) -> Self {
1030        Self::new(
1031            math::sin(self.x),
1032            math::sin(self.y),
1033            math::sin(self.z),
1034            math::sin(self.w),
1035        )
1036    }
1037
1038    /// Returns a tuple of two vectors containing the sine and cosine for each element of `self`.
1039    #[inline]
1040    #[must_use]
1041    pub fn sin_cos(self) -> (Self, Self) {
1042        let (sin_x, cos_x) = math::sin_cos(self.x);
1043        let (sin_y, cos_y) = math::sin_cos(self.y);
1044        let (sin_z, cos_z) = math::sin_cos(self.z);
1045        let (sin_w, cos_w) = math::sin_cos(self.w);
1046
1047        (
1048            Self::new(sin_x, sin_y, sin_z, sin_w),
1049            Self::new(cos_x, cos_y, cos_z, cos_w),
1050        )
1051    }
1052
1053    /// Returns a vector containing the reciprocal `1.0/n` of each element of `self`.
1054    #[inline]
1055    #[must_use]
1056    pub fn recip(self) -> Self {
1057        Self::new(1.0 / self.x, 1.0 / self.y, 1.0 / self.z, 1.0 / self.w)
1058    }
1059
1060    /// Performs a linear interpolation between `self` and `rhs` based on the value `s`, using the
1061    /// form `self * (1.0 - s) + rhs * s`.
1062    ///
1063    /// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result will
1064    /// be equal to `rhs`. When `s` is outside of the range `[0, 1]`, the result is linearly
1065    /// extrapolated.
1066    ///
1067    /// The result is guaranteed to be `self` at `s == 0.0` and `rhs` at `s == 1.0`, even when the
1068    /// values differ greatly in magnitude, but it is not monotonic in `s` for nearly equal inputs
1069    /// and may not preserve equal inputs exactly. Consider [`lerp_monotonic`](Self::lerp_monotonic)
1070    /// instead when interpolating between values that may be equal or nearly equal.
1071    #[doc(alias = "mix")]
1072    #[inline]
1073    #[must_use]
1074    pub fn lerp(self, rhs: Self, s: f64) -> Self {
1075        self * (1.0 - s) + rhs * s
1076    }
1077
1078    /// Performs a linear interpolation between `self` and `rhs` based on the value `s`, using the
1079    /// monotonic form `self + (rhs - self) * s`.
1080    ///
1081    /// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result will
1082    /// be equal to `rhs`. When `s` is outside of the range `[0, 1]`, the result is linearly
1083    /// extrapolated.
1084    ///
1085    /// Prefer this over [`lerp`](Self::lerp) when interpolating between values that may be equal or
1086    /// nearly equal: the result is monotonic in `s` and equal inputs are preserved exactly, avoiding
1087    /// the rounding jitter that [`lerp`](Self::lerp) can introduce. The tradeoff is that
1088    /// `rhs - self` is evaluated first, so this is less accurate than [`lerp`](Self::lerp) when
1089    /// `self` and `rhs` differ greatly in magnitude, and overflows to infinity when they have
1090    /// opposite signs and large magnitudes.
1091    ///
1092    /// On SIMD back-ends the multiply and add are fused when the target supports it, which has a
1093    /// single rounding step and can be more accurate than a separate multiply and add.
1094    #[doc(alias = "mix")]
1095    #[inline]
1096    #[must_use]
1097    pub fn lerp_monotonic(self, rhs: Self, s: f64) -> Self {
1098        self + (rhs - self) * s
1099    }
1100
1101    /// Moves towards `rhs` based on the value `d`.
1102    ///
1103    /// When `d` is `0.0`, the result will be equal to `self`. When `d` is equal to
1104    /// `self.distance(rhs)`, the result will be equal to `rhs`. Will not go past `rhs`.
1105    #[inline]
1106    #[must_use]
1107    pub fn move_towards(self, rhs: Self, d: f64) -> Self {
1108        let a = rhs - self;
1109        let len = a.length();
1110        if len <= d || len <= 1e-4 {
1111            return rhs;
1112        }
1113        self + a / len * d
1114    }
1115
1116    /// Calculates the midpoint between `self` and `rhs`.
1117    ///
1118    /// The midpoint is the average of, or halfway point between, two vectors.
1119    /// `a.midpoint(b)` should yield the same result as `a.lerp(b, 0.5)`
1120    /// while being slightly cheaper to compute.
1121    #[inline]
1122    pub fn midpoint(self, rhs: Self) -> Self {
1123        (self + rhs) * 0.5
1124    }
1125
1126    /// Returns true if the absolute difference of all elements between `self` and `rhs` is
1127    /// less than or equal to `max_abs_diff`.
1128    ///
1129    /// This can be used to compare if two vectors contain similar elements. It works best when
1130    /// comparing with a known value. The `max_abs_diff` that should be used used depends on
1131    /// the values being compared against.
1132    ///
1133    /// For more see
1134    /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/).
1135    #[inline]
1136    #[must_use]
1137    pub fn abs_diff_eq(self, rhs: Self, max_abs_diff: f64) -> bool {
1138        self.sub(rhs).abs().cmple(Self::splat(max_abs_diff)).all()
1139    }
1140
1141    /// Returns a vector with a length no less than `min` and no more than `max`.
1142    ///
1143    /// # Panics
1144    ///
1145    /// Will panic if `min` is greater than `max`, or if either `min` or `max` is negative, when `glam_assert` is enabled.
1146    #[inline]
1147    #[must_use]
1148    #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
1149    pub fn clamp_length(self, min: f64, max: f64) -> Self {
1150        glam_assert!(0.0 <= min);
1151        glam_assert!(min <= max);
1152        let length_sq = self.length_squared();
1153        if length_sq < min * min {
1154            min * (self / math::sqrt(length_sq))
1155        } else if length_sq > max * max {
1156            max * (self / math::sqrt(length_sq))
1157        } else {
1158            self
1159        }
1160    }
1161
1162    /// Returns a vector with a length no more than `max`.
1163    ///
1164    /// # Panics
1165    ///
1166    /// Will panic if `max` is negative when `glam_assert` is enabled.
1167    #[inline]
1168    #[must_use]
1169    #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
1170    pub fn clamp_length_max(self, max: f64) -> Self {
1171        glam_assert!(0.0 <= max);
1172        let length_sq = self.length_squared();
1173        if length_sq > max * max {
1174            max * (self / math::sqrt(length_sq))
1175        } else {
1176            self
1177        }
1178    }
1179
1180    /// Returns a vector with a length no less than `min`.
1181    ///
1182    /// # Panics
1183    ///
1184    /// Will panic if `min` is negative when `glam_assert` is enabled.
1185    #[inline]
1186    #[must_use]
1187    #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
1188    pub fn clamp_length_min(self, min: f64) -> Self {
1189        glam_assert!(0.0 <= min);
1190        let length_sq = self.length_squared();
1191        if length_sq < min * min {
1192            min * (self / math::sqrt(length_sq))
1193        } else {
1194            self
1195        }
1196    }
1197
1198    /// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding
1199    /// error, yielding a more accurate result than an unfused multiply-add.
1200    ///
1201    /// Using `mul_add` *may* be more performant than an unfused multiply-add if the target
1202    /// architecture has a dedicated fma CPU instruction. However, this is not always true,
1203    /// and will be heavily dependant on designing algorithms with specific target hardware in
1204    /// mind.
1205    #[inline]
1206    #[must_use]
1207    pub fn mul_add(self, a: Self, b: Self) -> Self {
1208        Self::new(
1209            math::mul_add(self.x, a.x, b.x),
1210            math::mul_add(self.y, a.y, b.y),
1211            math::mul_add(self.z, a.z, b.z),
1212            math::mul_add(self.w, a.w, b.w),
1213        )
1214    }
1215
1216    /// Returns the reflection vector for a given incident vector `self` and surface normal
1217    /// `normal`.
1218    ///
1219    /// `normal` must be normalized.
1220    ///
1221    /// # Panics
1222    ///
1223    /// Will panic if `normal` is not normalized when `glam_assert` is enabled.
1224    #[inline]
1225    #[must_use]
1226    #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
1227    pub fn reflect(self, normal: Self) -> Self {
1228        glam_assert!(normal.is_normalized());
1229        self - 2.0 * self.dot(normal) * normal
1230    }
1231
1232    /// Returns the refraction direction for a given incident vector `self`, surface normal
1233    /// `normal` and ratio of indices of refraction, `eta`. When total internal reflection occurs,
1234    /// a zero vector will be returned.
1235    ///
1236    /// `self` and `normal` must be normalized.
1237    ///
1238    /// # Panics
1239    ///
1240    /// Will panic if `self` or `normal` is not normalized when `glam_assert` is enabled.
1241    #[inline]
1242    #[must_use]
1243    #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
1244    pub fn refract(self, normal: Self, eta: f64) -> Self {
1245        glam_assert!(self.is_normalized());
1246        glam_assert!(normal.is_normalized());
1247        let n_dot_i = normal.dot(self);
1248        let k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
1249        if k >= 0.0 {
1250            eta * self - (eta * n_dot_i + math::sqrt(k)) * normal
1251        } else {
1252            Self::ZERO
1253        }
1254    }
1255
1256    /// Casts all elements of `self` to `f32`.
1257    #[inline]
1258    #[must_use]
1259    pub fn as_vec4(self) -> crate::Vec4 {
1260        crate::Vec4::new(self.x as f32, self.y as f32, self.z as f32, self.w as f32)
1261    }
1262
1263    /// Casts all elements of `self` to `i8`.
1264    #[cfg(feature = "i8")]
1265    #[inline]
1266    #[must_use]
1267    pub fn as_i8vec4(self) -> crate::I8Vec4 {
1268        crate::I8Vec4::new(self.x as i8, self.y as i8, self.z as i8, self.w as i8)
1269    }
1270
1271    /// Casts all elements of `self` to `u8`.
1272    #[cfg(feature = "u8")]
1273    #[inline]
1274    #[must_use]
1275    pub fn as_u8vec4(self) -> crate::U8Vec4 {
1276        crate::U8Vec4::new(self.x as u8, self.y as u8, self.z as u8, self.w as u8)
1277    }
1278
1279    /// Casts all elements of `self` to `i16`.
1280    #[cfg(feature = "i16")]
1281    #[inline]
1282    #[must_use]
1283    pub fn as_i16vec4(self) -> crate::I16Vec4 {
1284        crate::I16Vec4::new(self.x as i16, self.y as i16, self.z as i16, self.w as i16)
1285    }
1286
1287    /// Casts all elements of `self` to `u16`.
1288    #[cfg(feature = "u16")]
1289    #[inline]
1290    #[must_use]
1291    pub fn as_u16vec4(self) -> crate::U16Vec4 {
1292        crate::U16Vec4::new(self.x as u16, self.y as u16, self.z as u16, self.w as u16)
1293    }
1294
1295    /// Casts all elements of `self` to `i32`.
1296    #[cfg(feature = "i32")]
1297    #[inline]
1298    #[must_use]
1299    pub fn as_ivec4(self) -> crate::IVec4 {
1300        crate::IVec4::new(self.x as i32, self.y as i32, self.z as i32, self.w as i32)
1301    }
1302
1303    /// Casts all elements of `self` to `u32`.
1304    #[cfg(feature = "u32")]
1305    #[inline]
1306    #[must_use]
1307    pub fn as_uvec4(self) -> crate::UVec4 {
1308        crate::UVec4::new(self.x as u32, self.y as u32, self.z as u32, self.w as u32)
1309    }
1310
1311    /// Casts all elements of `self` to `i64`.
1312    #[cfg(feature = "i64")]
1313    #[inline]
1314    #[must_use]
1315    pub fn as_i64vec4(self) -> crate::I64Vec4 {
1316        crate::I64Vec4::new(self.x as i64, self.y as i64, self.z as i64, self.w as i64)
1317    }
1318
1319    /// Casts all elements of `self` to `u64`.
1320    #[cfg(feature = "u64")]
1321    #[inline]
1322    #[must_use]
1323    pub fn as_u64vec4(self) -> crate::U64Vec4 {
1324        crate::U64Vec4::new(self.x as u64, self.y as u64, self.z as u64, self.w as u64)
1325    }
1326
1327    /// Casts all elements of `self` to `isize`.
1328    #[cfg(feature = "isize")]
1329    #[inline]
1330    #[must_use]
1331    pub fn as_isizevec4(self) -> crate::ISizeVec4 {
1332        crate::ISizeVec4::new(
1333            self.x as isize,
1334            self.y as isize,
1335            self.z as isize,
1336            self.w as isize,
1337        )
1338    }
1339
1340    /// Casts all elements of `self` to `usize`.
1341    #[cfg(feature = "usize")]
1342    #[inline]
1343    #[must_use]
1344    pub fn as_usizevec4(self) -> crate::USizeVec4 {
1345        crate::USizeVec4::new(
1346            self.x as usize,
1347            self.y as usize,
1348            self.z as usize,
1349            self.w as usize,
1350        )
1351    }
1352}
1353
1354impl Default for DVec4 {
1355    #[inline(always)]
1356    fn default() -> Self {
1357        Self::ZERO
1358    }
1359}
1360
1361impl Div for DVec4 {
1362    type Output = Self;
1363    #[inline]
1364    fn div(self, rhs: Self) -> Self {
1365        Self::new(
1366            self.x.div(rhs.x),
1367            self.y.div(rhs.y),
1368            self.z.div(rhs.z),
1369            self.w.div(rhs.w),
1370        )
1371    }
1372}
1373
1374impl Div<&Self> for DVec4 {
1375    type Output = Self;
1376    #[inline]
1377    fn div(self, rhs: &Self) -> Self {
1378        self.div(*rhs)
1379    }
1380}
1381
1382impl Div<&DVec4> for &DVec4 {
1383    type Output = DVec4;
1384    #[inline]
1385    fn div(self, rhs: &DVec4) -> DVec4 {
1386        (*self).div(*rhs)
1387    }
1388}
1389
1390impl Div<DVec4> for &DVec4 {
1391    type Output = DVec4;
1392    #[inline]
1393    fn div(self, rhs: DVec4) -> DVec4 {
1394        (*self).div(rhs)
1395    }
1396}
1397
1398impl DivAssign for DVec4 {
1399    #[inline]
1400    fn div_assign(&mut self, rhs: Self) {
1401        self.x.div_assign(rhs.x);
1402        self.y.div_assign(rhs.y);
1403        self.z.div_assign(rhs.z);
1404        self.w.div_assign(rhs.w);
1405    }
1406}
1407
1408impl DivAssign<&Self> for DVec4 {
1409    #[inline]
1410    fn div_assign(&mut self, rhs: &Self) {
1411        self.div_assign(*rhs);
1412    }
1413}
1414
1415impl Div<f64> for DVec4 {
1416    type Output = Self;
1417    #[inline]
1418    fn div(self, rhs: f64) -> Self {
1419        Self::new(
1420            self.x.div(rhs),
1421            self.y.div(rhs),
1422            self.z.div(rhs),
1423            self.w.div(rhs),
1424        )
1425    }
1426}
1427
1428impl Div<&f64> for DVec4 {
1429    type Output = Self;
1430    #[inline]
1431    fn div(self, rhs: &f64) -> Self {
1432        self.div(*rhs)
1433    }
1434}
1435
1436impl Div<&f64> for &DVec4 {
1437    type Output = DVec4;
1438    #[inline]
1439    fn div(self, rhs: &f64) -> DVec4 {
1440        (*self).div(*rhs)
1441    }
1442}
1443
1444impl Div<f64> for &DVec4 {
1445    type Output = DVec4;
1446    #[inline]
1447    fn div(self, rhs: f64) -> DVec4 {
1448        (*self).div(rhs)
1449    }
1450}
1451
1452impl DivAssign<f64> for DVec4 {
1453    #[inline]
1454    fn div_assign(&mut self, rhs: f64) {
1455        self.x.div_assign(rhs);
1456        self.y.div_assign(rhs);
1457        self.z.div_assign(rhs);
1458        self.w.div_assign(rhs);
1459    }
1460}
1461
1462impl DivAssign<&f64> for DVec4 {
1463    #[inline]
1464    fn div_assign(&mut self, rhs: &f64) {
1465        self.div_assign(*rhs);
1466    }
1467}
1468
1469impl Div<DVec4> for f64 {
1470    type Output = DVec4;
1471    #[inline]
1472    fn div(self, rhs: DVec4) -> DVec4 {
1473        DVec4::new(
1474            self.div(rhs.x),
1475            self.div(rhs.y),
1476            self.div(rhs.z),
1477            self.div(rhs.w),
1478        )
1479    }
1480}
1481
1482impl Div<&DVec4> for f64 {
1483    type Output = DVec4;
1484    #[inline]
1485    fn div(self, rhs: &DVec4) -> DVec4 {
1486        self.div(*rhs)
1487    }
1488}
1489
1490impl Div<&DVec4> for &f64 {
1491    type Output = DVec4;
1492    #[inline]
1493    fn div(self, rhs: &DVec4) -> DVec4 {
1494        (*self).div(*rhs)
1495    }
1496}
1497
1498impl Div<DVec4> for &f64 {
1499    type Output = DVec4;
1500    #[inline]
1501    fn div(self, rhs: DVec4) -> DVec4 {
1502        (*self).div(rhs)
1503    }
1504}
1505
1506impl Mul for DVec4 {
1507    type Output = Self;
1508    #[inline]
1509    fn mul(self, rhs: Self) -> Self {
1510        Self::new(
1511            self.x.mul(rhs.x),
1512            self.y.mul(rhs.y),
1513            self.z.mul(rhs.z),
1514            self.w.mul(rhs.w),
1515        )
1516    }
1517}
1518
1519impl Mul<&Self> for DVec4 {
1520    type Output = Self;
1521    #[inline]
1522    fn mul(self, rhs: &Self) -> Self {
1523        self.mul(*rhs)
1524    }
1525}
1526
1527impl Mul<&DVec4> for &DVec4 {
1528    type Output = DVec4;
1529    #[inline]
1530    fn mul(self, rhs: &DVec4) -> DVec4 {
1531        (*self).mul(*rhs)
1532    }
1533}
1534
1535impl Mul<DVec4> for &DVec4 {
1536    type Output = DVec4;
1537    #[inline]
1538    fn mul(self, rhs: DVec4) -> DVec4 {
1539        (*self).mul(rhs)
1540    }
1541}
1542
1543impl MulAssign for DVec4 {
1544    #[inline]
1545    fn mul_assign(&mut self, rhs: Self) {
1546        self.x.mul_assign(rhs.x);
1547        self.y.mul_assign(rhs.y);
1548        self.z.mul_assign(rhs.z);
1549        self.w.mul_assign(rhs.w);
1550    }
1551}
1552
1553impl MulAssign<&Self> for DVec4 {
1554    #[inline]
1555    fn mul_assign(&mut self, rhs: &Self) {
1556        self.mul_assign(*rhs);
1557    }
1558}
1559
1560impl Mul<f64> for DVec4 {
1561    type Output = Self;
1562    #[inline]
1563    fn mul(self, rhs: f64) -> Self {
1564        Self::new(
1565            self.x.mul(rhs),
1566            self.y.mul(rhs),
1567            self.z.mul(rhs),
1568            self.w.mul(rhs),
1569        )
1570    }
1571}
1572
1573impl Mul<&f64> for DVec4 {
1574    type Output = Self;
1575    #[inline]
1576    fn mul(self, rhs: &f64) -> Self {
1577        self.mul(*rhs)
1578    }
1579}
1580
1581impl Mul<&f64> for &DVec4 {
1582    type Output = DVec4;
1583    #[inline]
1584    fn mul(self, rhs: &f64) -> DVec4 {
1585        (*self).mul(*rhs)
1586    }
1587}
1588
1589impl Mul<f64> for &DVec4 {
1590    type Output = DVec4;
1591    #[inline]
1592    fn mul(self, rhs: f64) -> DVec4 {
1593        (*self).mul(rhs)
1594    }
1595}
1596
1597impl MulAssign<f64> for DVec4 {
1598    #[inline]
1599    fn mul_assign(&mut self, rhs: f64) {
1600        self.x.mul_assign(rhs);
1601        self.y.mul_assign(rhs);
1602        self.z.mul_assign(rhs);
1603        self.w.mul_assign(rhs);
1604    }
1605}
1606
1607impl MulAssign<&f64> for DVec4 {
1608    #[inline]
1609    fn mul_assign(&mut self, rhs: &f64) {
1610        self.mul_assign(*rhs);
1611    }
1612}
1613
1614impl Mul<DVec4> for f64 {
1615    type Output = DVec4;
1616    #[inline]
1617    fn mul(self, rhs: DVec4) -> DVec4 {
1618        DVec4::new(
1619            self.mul(rhs.x),
1620            self.mul(rhs.y),
1621            self.mul(rhs.z),
1622            self.mul(rhs.w),
1623        )
1624    }
1625}
1626
1627impl Mul<&DVec4> for f64 {
1628    type Output = DVec4;
1629    #[inline]
1630    fn mul(self, rhs: &DVec4) -> DVec4 {
1631        self.mul(*rhs)
1632    }
1633}
1634
1635impl Mul<&DVec4> for &f64 {
1636    type Output = DVec4;
1637    #[inline]
1638    fn mul(self, rhs: &DVec4) -> DVec4 {
1639        (*self).mul(*rhs)
1640    }
1641}
1642
1643impl Mul<DVec4> for &f64 {
1644    type Output = DVec4;
1645    #[inline]
1646    fn mul(self, rhs: DVec4) -> DVec4 {
1647        (*self).mul(rhs)
1648    }
1649}
1650
1651impl Add for DVec4 {
1652    type Output = Self;
1653    #[inline]
1654    fn add(self, rhs: Self) -> Self {
1655        Self::new(
1656            self.x.add(rhs.x),
1657            self.y.add(rhs.y),
1658            self.z.add(rhs.z),
1659            self.w.add(rhs.w),
1660        )
1661    }
1662}
1663
1664impl Add<&Self> for DVec4 {
1665    type Output = Self;
1666    #[inline]
1667    fn add(self, rhs: &Self) -> Self {
1668        self.add(*rhs)
1669    }
1670}
1671
1672impl Add<&DVec4> for &DVec4 {
1673    type Output = DVec4;
1674    #[inline]
1675    fn add(self, rhs: &DVec4) -> DVec4 {
1676        (*self).add(*rhs)
1677    }
1678}
1679
1680impl Add<DVec4> for &DVec4 {
1681    type Output = DVec4;
1682    #[inline]
1683    fn add(self, rhs: DVec4) -> DVec4 {
1684        (*self).add(rhs)
1685    }
1686}
1687
1688impl AddAssign for DVec4 {
1689    #[inline]
1690    fn add_assign(&mut self, rhs: Self) {
1691        self.x.add_assign(rhs.x);
1692        self.y.add_assign(rhs.y);
1693        self.z.add_assign(rhs.z);
1694        self.w.add_assign(rhs.w);
1695    }
1696}
1697
1698impl AddAssign<&Self> for DVec4 {
1699    #[inline]
1700    fn add_assign(&mut self, rhs: &Self) {
1701        self.add_assign(*rhs);
1702    }
1703}
1704
1705impl Add<f64> for DVec4 {
1706    type Output = Self;
1707    #[inline]
1708    fn add(self, rhs: f64) -> Self {
1709        Self::new(
1710            self.x.add(rhs),
1711            self.y.add(rhs),
1712            self.z.add(rhs),
1713            self.w.add(rhs),
1714        )
1715    }
1716}
1717
1718impl Add<&f64> for DVec4 {
1719    type Output = Self;
1720    #[inline]
1721    fn add(self, rhs: &f64) -> Self {
1722        self.add(*rhs)
1723    }
1724}
1725
1726impl Add<&f64> for &DVec4 {
1727    type Output = DVec4;
1728    #[inline]
1729    fn add(self, rhs: &f64) -> DVec4 {
1730        (*self).add(*rhs)
1731    }
1732}
1733
1734impl Add<f64> for &DVec4 {
1735    type Output = DVec4;
1736    #[inline]
1737    fn add(self, rhs: f64) -> DVec4 {
1738        (*self).add(rhs)
1739    }
1740}
1741
1742impl AddAssign<f64> for DVec4 {
1743    #[inline]
1744    fn add_assign(&mut self, rhs: f64) {
1745        self.x.add_assign(rhs);
1746        self.y.add_assign(rhs);
1747        self.z.add_assign(rhs);
1748        self.w.add_assign(rhs);
1749    }
1750}
1751
1752impl AddAssign<&f64> for DVec4 {
1753    #[inline]
1754    fn add_assign(&mut self, rhs: &f64) {
1755        self.add_assign(*rhs);
1756    }
1757}
1758
1759impl Add<DVec4> for f64 {
1760    type Output = DVec4;
1761    #[inline]
1762    fn add(self, rhs: DVec4) -> DVec4 {
1763        DVec4::new(
1764            self.add(rhs.x),
1765            self.add(rhs.y),
1766            self.add(rhs.z),
1767            self.add(rhs.w),
1768        )
1769    }
1770}
1771
1772impl Add<&DVec4> for f64 {
1773    type Output = DVec4;
1774    #[inline]
1775    fn add(self, rhs: &DVec4) -> DVec4 {
1776        self.add(*rhs)
1777    }
1778}
1779
1780impl Add<&DVec4> for &f64 {
1781    type Output = DVec4;
1782    #[inline]
1783    fn add(self, rhs: &DVec4) -> DVec4 {
1784        (*self).add(*rhs)
1785    }
1786}
1787
1788impl Add<DVec4> for &f64 {
1789    type Output = DVec4;
1790    #[inline]
1791    fn add(self, rhs: DVec4) -> DVec4 {
1792        (*self).add(rhs)
1793    }
1794}
1795
1796impl Sub for DVec4 {
1797    type Output = Self;
1798    #[inline]
1799    fn sub(self, rhs: Self) -> Self {
1800        Self::new(
1801            self.x.sub(rhs.x),
1802            self.y.sub(rhs.y),
1803            self.z.sub(rhs.z),
1804            self.w.sub(rhs.w),
1805        )
1806    }
1807}
1808
1809impl Sub<&Self> for DVec4 {
1810    type Output = Self;
1811    #[inline]
1812    fn sub(self, rhs: &Self) -> Self {
1813        self.sub(*rhs)
1814    }
1815}
1816
1817impl Sub<&DVec4> for &DVec4 {
1818    type Output = DVec4;
1819    #[inline]
1820    fn sub(self, rhs: &DVec4) -> DVec4 {
1821        (*self).sub(*rhs)
1822    }
1823}
1824
1825impl Sub<DVec4> for &DVec4 {
1826    type Output = DVec4;
1827    #[inline]
1828    fn sub(self, rhs: DVec4) -> DVec4 {
1829        (*self).sub(rhs)
1830    }
1831}
1832
1833impl SubAssign for DVec4 {
1834    #[inline]
1835    fn sub_assign(&mut self, rhs: Self) {
1836        self.x.sub_assign(rhs.x);
1837        self.y.sub_assign(rhs.y);
1838        self.z.sub_assign(rhs.z);
1839        self.w.sub_assign(rhs.w);
1840    }
1841}
1842
1843impl SubAssign<&Self> for DVec4 {
1844    #[inline]
1845    fn sub_assign(&mut self, rhs: &Self) {
1846        self.sub_assign(*rhs);
1847    }
1848}
1849
1850impl Sub<f64> for DVec4 {
1851    type Output = Self;
1852    #[inline]
1853    fn sub(self, rhs: f64) -> Self {
1854        Self::new(
1855            self.x.sub(rhs),
1856            self.y.sub(rhs),
1857            self.z.sub(rhs),
1858            self.w.sub(rhs),
1859        )
1860    }
1861}
1862
1863impl Sub<&f64> for DVec4 {
1864    type Output = Self;
1865    #[inline]
1866    fn sub(self, rhs: &f64) -> Self {
1867        self.sub(*rhs)
1868    }
1869}
1870
1871impl Sub<&f64> for &DVec4 {
1872    type Output = DVec4;
1873    #[inline]
1874    fn sub(self, rhs: &f64) -> DVec4 {
1875        (*self).sub(*rhs)
1876    }
1877}
1878
1879impl Sub<f64> for &DVec4 {
1880    type Output = DVec4;
1881    #[inline]
1882    fn sub(self, rhs: f64) -> DVec4 {
1883        (*self).sub(rhs)
1884    }
1885}
1886
1887impl SubAssign<f64> for DVec4 {
1888    #[inline]
1889    fn sub_assign(&mut self, rhs: f64) {
1890        self.x.sub_assign(rhs);
1891        self.y.sub_assign(rhs);
1892        self.z.sub_assign(rhs);
1893        self.w.sub_assign(rhs);
1894    }
1895}
1896
1897impl SubAssign<&f64> for DVec4 {
1898    #[inline]
1899    fn sub_assign(&mut self, rhs: &f64) {
1900        self.sub_assign(*rhs);
1901    }
1902}
1903
1904impl Sub<DVec4> for f64 {
1905    type Output = DVec4;
1906    #[inline]
1907    fn sub(self, rhs: DVec4) -> DVec4 {
1908        DVec4::new(
1909            self.sub(rhs.x),
1910            self.sub(rhs.y),
1911            self.sub(rhs.z),
1912            self.sub(rhs.w),
1913        )
1914    }
1915}
1916
1917impl Sub<&DVec4> for f64 {
1918    type Output = DVec4;
1919    #[inline]
1920    fn sub(self, rhs: &DVec4) -> DVec4 {
1921        self.sub(*rhs)
1922    }
1923}
1924
1925impl Sub<&DVec4> for &f64 {
1926    type Output = DVec4;
1927    #[inline]
1928    fn sub(self, rhs: &DVec4) -> DVec4 {
1929        (*self).sub(*rhs)
1930    }
1931}
1932
1933impl Sub<DVec4> for &f64 {
1934    type Output = DVec4;
1935    #[inline]
1936    fn sub(self, rhs: DVec4) -> DVec4 {
1937        (*self).sub(rhs)
1938    }
1939}
1940
1941impl Rem for DVec4 {
1942    type Output = Self;
1943    #[inline]
1944    fn rem(self, rhs: Self) -> Self {
1945        Self::new(
1946            self.x.rem(rhs.x),
1947            self.y.rem(rhs.y),
1948            self.z.rem(rhs.z),
1949            self.w.rem(rhs.w),
1950        )
1951    }
1952}
1953
1954impl Rem<&Self> for DVec4 {
1955    type Output = Self;
1956    #[inline]
1957    fn rem(self, rhs: &Self) -> Self {
1958        self.rem(*rhs)
1959    }
1960}
1961
1962impl Rem<&DVec4> for &DVec4 {
1963    type Output = DVec4;
1964    #[inline]
1965    fn rem(self, rhs: &DVec4) -> DVec4 {
1966        (*self).rem(*rhs)
1967    }
1968}
1969
1970impl Rem<DVec4> for &DVec4 {
1971    type Output = DVec4;
1972    #[inline]
1973    fn rem(self, rhs: DVec4) -> DVec4 {
1974        (*self).rem(rhs)
1975    }
1976}
1977
1978impl RemAssign for DVec4 {
1979    #[inline]
1980    fn rem_assign(&mut self, rhs: Self) {
1981        self.x.rem_assign(rhs.x);
1982        self.y.rem_assign(rhs.y);
1983        self.z.rem_assign(rhs.z);
1984        self.w.rem_assign(rhs.w);
1985    }
1986}
1987
1988impl RemAssign<&Self> for DVec4 {
1989    #[inline]
1990    fn rem_assign(&mut self, rhs: &Self) {
1991        self.rem_assign(*rhs);
1992    }
1993}
1994
1995impl Rem<f64> for DVec4 {
1996    type Output = Self;
1997    #[inline]
1998    fn rem(self, rhs: f64) -> Self {
1999        Self::new(
2000            self.x.rem(rhs),
2001            self.y.rem(rhs),
2002            self.z.rem(rhs),
2003            self.w.rem(rhs),
2004        )
2005    }
2006}
2007
2008impl Rem<&f64> for DVec4 {
2009    type Output = Self;
2010    #[inline]
2011    fn rem(self, rhs: &f64) -> Self {
2012        self.rem(*rhs)
2013    }
2014}
2015
2016impl Rem<&f64> for &DVec4 {
2017    type Output = DVec4;
2018    #[inline]
2019    fn rem(self, rhs: &f64) -> DVec4 {
2020        (*self).rem(*rhs)
2021    }
2022}
2023
2024impl Rem<f64> for &DVec4 {
2025    type Output = DVec4;
2026    #[inline]
2027    fn rem(self, rhs: f64) -> DVec4 {
2028        (*self).rem(rhs)
2029    }
2030}
2031
2032impl RemAssign<f64> for DVec4 {
2033    #[inline]
2034    fn rem_assign(&mut self, rhs: f64) {
2035        self.x.rem_assign(rhs);
2036        self.y.rem_assign(rhs);
2037        self.z.rem_assign(rhs);
2038        self.w.rem_assign(rhs);
2039    }
2040}
2041
2042impl RemAssign<&f64> for DVec4 {
2043    #[inline]
2044    fn rem_assign(&mut self, rhs: &f64) {
2045        self.rem_assign(*rhs);
2046    }
2047}
2048
2049impl Rem<DVec4> for f64 {
2050    type Output = DVec4;
2051    #[inline]
2052    fn rem(self, rhs: DVec4) -> DVec4 {
2053        DVec4::new(
2054            self.rem(rhs.x),
2055            self.rem(rhs.y),
2056            self.rem(rhs.z),
2057            self.rem(rhs.w),
2058        )
2059    }
2060}
2061
2062impl Rem<&DVec4> for f64 {
2063    type Output = DVec4;
2064    #[inline]
2065    fn rem(self, rhs: &DVec4) -> DVec4 {
2066        self.rem(*rhs)
2067    }
2068}
2069
2070impl Rem<&DVec4> for &f64 {
2071    type Output = DVec4;
2072    #[inline]
2073    fn rem(self, rhs: &DVec4) -> DVec4 {
2074        (*self).rem(*rhs)
2075    }
2076}
2077
2078impl Rem<DVec4> for &f64 {
2079    type Output = DVec4;
2080    #[inline]
2081    fn rem(self, rhs: DVec4) -> DVec4 {
2082        (*self).rem(rhs)
2083    }
2084}
2085
2086impl AsRef<[f64; 4]> for DVec4 {
2087    #[inline]
2088    fn as_ref(&self) -> &[f64; 4] {
2089        unsafe { &*(self as *const Self as *const [f64; 4]) }
2090    }
2091}
2092
2093impl AsMut<[f64; 4]> for DVec4 {
2094    #[inline]
2095    fn as_mut(&mut self) -> &mut [f64; 4] {
2096        unsafe { &mut *(self as *mut Self as *mut [f64; 4]) }
2097    }
2098}
2099
2100impl Sum for DVec4 {
2101    #[inline]
2102    fn sum<I>(iter: I) -> Self
2103    where
2104        I: Iterator<Item = Self>,
2105    {
2106        iter.fold(Self::ZERO, Self::add)
2107    }
2108}
2109
2110impl<'a> Sum<&'a Self> for DVec4 {
2111    #[inline]
2112    fn sum<I>(iter: I) -> Self
2113    where
2114        I: Iterator<Item = &'a Self>,
2115    {
2116        iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
2117    }
2118}
2119
2120impl Product for DVec4 {
2121    #[inline]
2122    fn product<I>(iter: I) -> Self
2123    where
2124        I: Iterator<Item = Self>,
2125    {
2126        iter.fold(Self::ONE, Self::mul)
2127    }
2128}
2129
2130impl<'a> Product<&'a Self> for DVec4 {
2131    #[inline]
2132    fn product<I>(iter: I) -> Self
2133    where
2134        I: Iterator<Item = &'a Self>,
2135    {
2136        iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
2137    }
2138}
2139
2140impl Neg for DVec4 {
2141    type Output = Self;
2142    #[inline]
2143    fn neg(self) -> Self {
2144        Self::new(self.x.neg(), self.y.neg(), self.z.neg(), self.w.neg())
2145    }
2146}
2147
2148impl Neg for &DVec4 {
2149    type Output = DVec4;
2150    #[inline]
2151    fn neg(self) -> DVec4 {
2152        (*self).neg()
2153    }
2154}
2155
2156impl Index<usize> for DVec4 {
2157    type Output = f64;
2158    #[inline]
2159    #[track_caller]
2160    fn index(&self, index: usize) -> &Self::Output {
2161        match index {
2162            0 => &self.x,
2163            1 => &self.y,
2164            2 => &self.z,
2165            3 => &self.w,
2166            _ => panic!("index out of bounds"),
2167        }
2168    }
2169}
2170
2171impl IndexMut<usize> for DVec4 {
2172    #[inline]
2173    #[track_caller]
2174    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
2175        match index {
2176            0 => &mut self.x,
2177            1 => &mut self.y,
2178            2 => &mut self.z,
2179            3 => &mut self.w,
2180            _ => panic!("index out of bounds"),
2181        }
2182    }
2183}
2184
2185impl fmt::Display for DVec4 {
2186    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2187        if let Some(p) = f.precision() {
2188            write!(
2189                f,
2190                "[{:.*}, {:.*}, {:.*}, {:.*}]",
2191                p, self.x, p, self.y, p, self.z, p, self.w
2192            )
2193        } else {
2194            write!(f, "[{}, {}, {}, {}]", self.x, self.y, self.z, self.w)
2195        }
2196    }
2197}
2198
2199impl fmt::Debug for DVec4 {
2200    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
2201        fmt.debug_tuple(stringify!(DVec4))
2202            .field(&self.x)
2203            .field(&self.y)
2204            .field(&self.z)
2205            .field(&self.w)
2206            .finish()
2207    }
2208}
2209
2210impl From<[f64; 4]> for DVec4 {
2211    #[inline]
2212    fn from(a: [f64; 4]) -> Self {
2213        Self::new(a[0], a[1], a[2], a[3])
2214    }
2215}
2216
2217impl From<DVec4> for [f64; 4] {
2218    #[inline]
2219    fn from(v: DVec4) -> Self {
2220        [v.x, v.y, v.z, v.w]
2221    }
2222}
2223
2224impl From<(f64, f64, f64, f64)> for DVec4 {
2225    #[inline]
2226    fn from(t: (f64, f64, f64, f64)) -> Self {
2227        Self::new(t.0, t.1, t.2, t.3)
2228    }
2229}
2230
2231impl From<DVec4> for (f64, f64, f64, f64) {
2232    #[inline]
2233    fn from(v: DVec4) -> Self {
2234        (v.x, v.y, v.z, v.w)
2235    }
2236}
2237
2238impl From<(DVec3, f64)> for DVec4 {
2239    #[inline]
2240    fn from((v, w): (DVec3, f64)) -> Self {
2241        Self::new(v.x, v.y, v.z, w)
2242    }
2243}
2244
2245impl From<(f64, DVec3)> for DVec4 {
2246    #[inline]
2247    fn from((x, v): (f64, DVec3)) -> Self {
2248        Self::new(x, v.x, v.y, v.z)
2249    }
2250}
2251
2252impl From<(DVec2, f64, f64)> for DVec4 {
2253    #[inline]
2254    fn from((v, z, w): (DVec2, f64, f64)) -> Self {
2255        Self::new(v.x, v.y, z, w)
2256    }
2257}
2258
2259impl From<(DVec2, DVec2)> for DVec4 {
2260    #[inline]
2261    fn from((v, u): (DVec2, DVec2)) -> Self {
2262        Self::new(v.x, v.y, u.x, u.y)
2263    }
2264}
2265
2266impl From<Vec4> for DVec4 {
2267    #[inline]
2268    fn from(v: Vec4) -> Self {
2269        Self::new(
2270            f64::from(v.x),
2271            f64::from(v.y),
2272            f64::from(v.z),
2273            f64::from(v.w),
2274        )
2275    }
2276}
2277
2278#[cfg(feature = "i32")]
2279impl From<IVec4> for DVec4 {
2280    #[inline]
2281    fn from(v: IVec4) -> Self {
2282        Self::new(
2283            f64::from(v.x),
2284            f64::from(v.y),
2285            f64::from(v.z),
2286            f64::from(v.w),
2287        )
2288    }
2289}
2290
2291#[cfg(feature = "u32")]
2292impl From<UVec4> for DVec4 {
2293    #[inline]
2294    fn from(v: UVec4) -> Self {
2295        Self::new(
2296            f64::from(v.x),
2297            f64::from(v.y),
2298            f64::from(v.z),
2299            f64::from(v.w),
2300        )
2301    }
2302}
2303
2304impl From<BVec4> for DVec4 {
2305    #[inline]
2306    fn from(v: BVec4) -> Self {
2307        Self::new(
2308            f64::from(v.x),
2309            f64::from(v.y),
2310            f64::from(v.z),
2311            f64::from(v.w),
2312        )
2313    }
2314}
2315
2316#[cfg(not(feature = "scalar-math"))]
2317impl From<BVec4A> for DVec4 {
2318    #[inline]
2319    fn from(v: BVec4A) -> Self {
2320        let bool_array: [bool; 4] = v.into();
2321        Self::new(
2322            f64::from(bool_array[0]),
2323            f64::from(bool_array[1]),
2324            f64::from(bool_array[2]),
2325            f64::from(bool_array[3]),
2326        )
2327    }
2328}