glam/f64/
dvec3.rs

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