Skip to main content

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