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 a mask indicating which components are negative.
519    ///
520    /// An element is negative if it has a negative sign, including -0.0, NaNs with negative sign
521    /// bit and negative infinity.
522    #[inline]
523    #[must_use]
524    pub fn is_negative_mask(self) -> BVec3 {
525        BVec3::new(
526            self.x.is_sign_negative(),
527            self.y.is_sign_negative(),
528            self.z.is_sign_negative(),
529        )
530    }
531
532    /// Returns `true` if, and only if, all elements are finite.  If any element is either
533    /// `NaN`, positive or negative infinity, this will return `false`.
534    #[inline]
535    #[must_use]
536    pub fn is_finite(self) -> bool {
537        self.x.is_finite() && self.y.is_finite() && self.z.is_finite()
538    }
539
540    /// Performs `is_finite` on each element of self, returning a vector mask of the results.
541    ///
542    /// In other words, this computes `[x.is_finite(), y.is_finite(), ...]`.
543    #[inline]
544    #[must_use]
545    pub fn is_finite_mask(self) -> BVec3 {
546        BVec3::new(self.x.is_finite(), self.y.is_finite(), self.z.is_finite())
547    }
548
549    /// Returns `true` if any elements are `NaN`.
550    #[inline]
551    #[must_use]
552    pub fn is_nan(self) -> bool {
553        self.x.is_nan() || self.y.is_nan() || self.z.is_nan()
554    }
555
556    /// Performs `is_nan` on each element of self, returning a vector mask of the results.
557    ///
558    /// In other words, this computes `[x.is_nan(), y.is_nan(), ...]`.
559    #[inline]
560    #[must_use]
561    pub fn is_nan_mask(self) -> BVec3 {
562        BVec3::new(self.x.is_nan(), self.y.is_nan(), self.z.is_nan())
563    }
564
565    /// Computes the length of `self`.
566    #[doc(alias = "magnitude")]
567    #[inline]
568    #[must_use]
569    pub fn length(self) -> f64 {
570        math::sqrt(self.dot(self))
571    }
572
573    /// Computes the squared length of `self`.
574    ///
575    /// This is faster than `length()` as it avoids a square root operation.
576    #[doc(alias = "magnitude2")]
577    #[inline]
578    #[must_use]
579    pub fn length_squared(self) -> f64 {
580        self.dot(self)
581    }
582
583    /// Computes `1.0 / length()`.
584    ///
585    /// For valid results, `self` must _not_ be of length zero.
586    #[inline]
587    #[must_use]
588    pub fn length_recip(self) -> f64 {
589        self.length().recip()
590    }
591
592    /// Computes the Euclidean distance between two points in space.
593    #[inline]
594    #[must_use]
595    pub fn distance(self, rhs: Self) -> f64 {
596        (self - rhs).length()
597    }
598
599    /// Compute the squared euclidean distance between two points in space.
600    #[inline]
601    #[must_use]
602    pub fn distance_squared(self, rhs: Self) -> f64 {
603        (self - rhs).length_squared()
604    }
605
606    /// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`.
607    #[inline]
608    #[must_use]
609    pub fn div_euclid(self, rhs: Self) -> Self {
610        Self::new(
611            math::div_euclid(self.x, rhs.x),
612            math::div_euclid(self.y, rhs.y),
613            math::div_euclid(self.z, rhs.z),
614        )
615    }
616
617    /// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`.
618    ///
619    /// [Euclidean division]: f64::rem_euclid
620    #[inline]
621    #[must_use]
622    pub fn rem_euclid(self, rhs: Self) -> Self {
623        Self::new(
624            math::rem_euclid(self.x, rhs.x),
625            math::rem_euclid(self.y, rhs.y),
626            math::rem_euclid(self.z, rhs.z),
627        )
628    }
629
630    /// Returns `self` normalized to length 1.0.
631    ///
632    /// For valid results, `self` must be finite and _not_ of length zero, nor very close to zero.
633    ///
634    /// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`].
635    ///
636    /// # Panics
637    ///
638    /// Will panic if the resulting normalized vector is not finite when `glam_assert` is enabled.
639    #[inline]
640    #[must_use]
641    pub fn normalize(self) -> Self {
642        #[allow(clippy::let_and_return)]
643        let normalized = self.mul(self.length_recip());
644        glam_assert!(normalized.is_finite());
645        normalized
646    }
647
648    /// Returns `self` normalized to length 1.0 if possible, else returns `None`.
649    ///
650    /// In particular, if the input is zero (or very close to zero), or non-finite,
651    /// the result of this operation will be `None`.
652    ///
653    /// See also [`Self::normalize_or_zero()`].
654    #[inline]
655    #[must_use]
656    pub fn try_normalize(self) -> Option<Self> {
657        let rcp = self.length_recip();
658        if rcp.is_finite() && rcp > 0.0 {
659            Some(self * rcp)
660        } else {
661            None
662        }
663    }
664
665    /// Returns `self` normalized to length 1.0 if possible, else returns a
666    /// fallback value.
667    ///
668    /// In particular, if the input is zero (or very close to zero), or non-finite,
669    /// the result of this operation will be the fallback value.
670    ///
671    /// See also [`Self::try_normalize()`].
672    #[inline]
673    #[must_use]
674    pub fn normalize_or(self, fallback: Self) -> Self {
675        let rcp = self.length_recip();
676        if rcp.is_finite() && rcp > 0.0 {
677            self * rcp
678        } else {
679            fallback
680        }
681    }
682
683    /// Returns `self` normalized to length 1.0 if possible, else returns zero.
684    ///
685    /// In particular, if the input is zero (or very close to zero), or non-finite,
686    /// the result of this operation will be zero.
687    ///
688    /// See also [`Self::try_normalize()`].
689    #[inline]
690    #[must_use]
691    pub fn normalize_or_zero(self) -> Self {
692        self.normalize_or(Self::ZERO)
693    }
694
695    /// Returns `self` normalized to length 1.0 and the length of `self`.
696    ///
697    /// If `self` is zero length then `(Self::X, 0.0)` is returned.
698    #[inline]
699    #[must_use]
700    pub fn normalize_and_length(self) -> (Self, f64) {
701        let length = self.length();
702        let rcp = 1.0 / length;
703        if rcp.is_finite() && rcp > 0.0 {
704            (self * rcp, length)
705        } else {
706            (Self::X, 0.0)
707        }
708    }
709
710    /// Returns whether `self` is length `1.0` or not.
711    ///
712    /// Uses a precision threshold of approximately `1e-4`.
713    #[inline]
714    #[must_use]
715    pub fn is_normalized(self) -> bool {
716        math::abs(self.length_squared() - 1.0) <= 2e-4
717    }
718
719    /// Returns the vector projection of `self` onto `rhs`.
720    ///
721    /// `rhs` must be of non-zero length.
722    ///
723    /// # Panics
724    ///
725    /// Will panic if `rhs` is zero length when `glam_assert` is enabled.
726    #[inline]
727    #[must_use]
728    pub fn project_onto(self, rhs: Self) -> Self {
729        let other_len_sq_rcp = rhs.dot(rhs).recip();
730        glam_assert!(other_len_sq_rcp.is_finite());
731        rhs * self.dot(rhs) * other_len_sq_rcp
732    }
733
734    /// Returns the vector rejection of `self` from `rhs`.
735    ///
736    /// The vector rejection is the vector perpendicular to the projection of `self` onto
737    /// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`.
738    ///
739    /// `rhs` must be of non-zero length.
740    ///
741    /// # Panics
742    ///
743    /// Will panic if `rhs` has a length of zero when `glam_assert` is enabled.
744    #[doc(alias("plane"))]
745    #[inline]
746    #[must_use]
747    pub fn reject_from(self, rhs: Self) -> Self {
748        self - self.project_onto(rhs)
749    }
750
751    /// Returns the vector projection of `self` onto `rhs`.
752    ///
753    /// `rhs` must be normalized.
754    ///
755    /// # Panics
756    ///
757    /// Will panic if `rhs` is not normalized when `glam_assert` is enabled.
758    #[inline]
759    #[must_use]
760    pub fn project_onto_normalized(self, rhs: Self) -> Self {
761        glam_assert!(rhs.is_normalized());
762        rhs * self.dot(rhs)
763    }
764
765    /// Returns the vector rejection of `self` from `rhs`.
766    ///
767    /// The vector rejection is the vector perpendicular to the projection of `self` onto
768    /// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`.
769    ///
770    /// `rhs` must be normalized.
771    ///
772    /// # Panics
773    ///
774    /// Will panic if `rhs` is not normalized when `glam_assert` is enabled.
775    #[doc(alias("plane"))]
776    #[inline]
777    #[must_use]
778    pub fn reject_from_normalized(self, rhs: Self) -> Self {
779        self - self.project_onto_normalized(rhs)
780    }
781
782    /// Returns a vector containing the nearest integer to a number for each element of `self`.
783    /// Round half-way cases away from 0.0.
784    #[inline]
785    #[must_use]
786    pub fn round(self) -> Self {
787        Self {
788            x: math::round(self.x),
789            y: math::round(self.y),
790            z: math::round(self.z),
791        }
792    }
793
794    /// Returns a vector containing the largest integer less than or equal to a number for each
795    /// element of `self`.
796    #[inline]
797    #[must_use]
798    pub fn floor(self) -> Self {
799        Self {
800            x: math::floor(self.x),
801            y: math::floor(self.y),
802            z: math::floor(self.z),
803        }
804    }
805
806    /// Returns a vector containing the smallest integer greater than or equal to a number for
807    /// each element of `self`.
808    #[inline]
809    #[must_use]
810    pub fn ceil(self) -> Self {
811        Self {
812            x: math::ceil(self.x),
813            y: math::ceil(self.y),
814            z: math::ceil(self.z),
815        }
816    }
817
818    /// Returns a vector containing the integer part each element of `self`. This means numbers are
819    /// always truncated towards zero.
820    #[inline]
821    #[must_use]
822    pub fn trunc(self) -> Self {
823        Self {
824            x: math::trunc(self.x),
825            y: math::trunc(self.y),
826            z: math::trunc(self.z),
827        }
828    }
829
830    /// Returns a vector containing `0.0` if `rhs < self` and 1.0 otherwise.
831    ///
832    /// Similar to glsl's step(edge, x), which translates into edge.step(x)
833    #[inline]
834    #[must_use]
835    pub fn step(self, rhs: Self) -> Self {
836        Self::select(rhs.cmplt(self), Self::ZERO, Self::ONE)
837    }
838
839    /// Returns a vector containing all elements of `self` clamped to the range of `[0, 1]`.
840    #[inline]
841    #[must_use]
842    pub fn saturate(self) -> Self {
843        self.clamp(Self::ZERO, Self::ONE)
844    }
845
846    /// Returns a vector containing the fractional part of the vector as `self - self.trunc()`.
847    ///
848    /// Note that this differs from the GLSL implementation of `fract` which returns
849    /// `self - self.floor()`.
850    ///
851    /// Note that this is fast but not precise for large numbers.
852    #[inline]
853    #[must_use]
854    pub fn fract(self) -> Self {
855        self - self.trunc()
856    }
857
858    /// Returns a vector containing the fractional part of the vector as `self - self.floor()`.
859    ///
860    /// Note that this differs from the Rust implementation of `fract` which returns
861    /// `self - self.trunc()`.
862    ///
863    /// Note that this is fast but not precise for large numbers.
864    #[inline]
865    #[must_use]
866    pub fn fract_gl(self) -> Self {
867        self - self.floor()
868    }
869
870    /// Returns a vector containing `e^self` (the exponential function) for each element of
871    /// `self`.
872    #[inline]
873    #[must_use]
874    pub fn exp(self) -> Self {
875        Self::new(math::exp(self.x), math::exp(self.y), math::exp(self.z))
876    }
877
878    /// Returns a vector containing `2^self` for each element of `self`.
879    #[inline]
880    #[must_use]
881    pub fn exp2(self) -> Self {
882        Self::new(math::exp2(self.x), math::exp2(self.y), math::exp2(self.z))
883    }
884
885    /// Returns a vector containing the natural logarithm for each element of `self`.
886    /// This returns NaN when the element is negative and negative infinity when the element is zero.
887    #[inline]
888    #[must_use]
889    pub fn ln(self) -> Self {
890        Self::new(math::ln(self.x), math::ln(self.y), math::ln(self.z))
891    }
892
893    /// Returns a vector containing the base 2 logarithm for each element of `self`.
894    /// This returns NaN when the element is negative and negative infinity when the element is zero.
895    #[inline]
896    #[must_use]
897    pub fn log2(self) -> Self {
898        Self::new(math::log2(self.x), math::log2(self.y), math::log2(self.z))
899    }
900
901    /// Returns a vector containing each element of `self` raised to the power of `n`.
902    #[inline]
903    #[must_use]
904    pub fn powf(self, n: f64) -> Self {
905        Self::new(
906            math::powf(self.x, n),
907            math::powf(self.y, n),
908            math::powf(self.z, n),
909        )
910    }
911
912    /// Returns a vector containing the square root for each element of `self`.
913    /// This returns NaN when the element is negative.
914    #[inline]
915    #[must_use]
916    pub fn sqrt(self) -> Self {
917        Self::new(math::sqrt(self.x), math::sqrt(self.y), math::sqrt(self.z))
918    }
919
920    /// Returns a vector containing the cosine for each element of `self`.
921    #[inline]
922    #[must_use]
923    pub fn cos(self) -> Self {
924        Self::new(math::cos(self.x), math::cos(self.y), math::cos(self.z))
925    }
926
927    /// Returns a vector containing the sine for each element of `self`.
928    #[inline]
929    #[must_use]
930    pub fn sin(self) -> Self {
931        Self::new(math::sin(self.x), math::sin(self.y), math::sin(self.z))
932    }
933
934    /// Returns a tuple of two vectors containing the sine and cosine for each element of `self`.
935    #[inline]
936    #[must_use]
937    pub fn sin_cos(self) -> (Self, Self) {
938        let (sin_x, cos_x) = math::sin_cos(self.x);
939        let (sin_y, cos_y) = math::sin_cos(self.y);
940        let (sin_z, cos_z) = math::sin_cos(self.z);
941
942        (
943            Self::new(sin_x, sin_y, sin_z),
944            Self::new(cos_x, cos_y, cos_z),
945        )
946    }
947
948    /// Returns a vector containing the reciprocal `1.0/n` of each element of `self`.
949    #[inline]
950    #[must_use]
951    pub fn recip(self) -> Self {
952        Self {
953            x: 1.0 / self.x,
954            y: 1.0 / self.y,
955            z: 1.0 / self.z,
956        }
957    }
958
959    /// Performs a linear interpolation between `self` and `rhs` based on the value `s`.
960    ///
961    /// When `s` is `0.0`, the result will be equal to `self`.  When `s` is `1.0`, the result
962    /// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly
963    /// extrapolated.
964    #[doc(alias = "mix")]
965    #[inline]
966    #[must_use]
967    pub fn lerp(self, rhs: Self, s: f64) -> Self {
968        self * (1.0 - s) + rhs * s
969    }
970
971    /// Moves towards `rhs` based on the value `d`.
972    ///
973    /// When `d` is `0.0`, the result will be equal to `self`. When `d` is equal to
974    /// `self.distance(rhs)`, the result will be equal to `rhs`. Will not go past `rhs`.
975    #[inline]
976    #[must_use]
977    pub fn move_towards(self, rhs: Self, d: f64) -> Self {
978        let a = rhs - self;
979        let len = a.length();
980        if len <= d || len <= 1e-4 {
981            return rhs;
982        }
983        self + a / len * d
984    }
985
986    /// Calculates the midpoint between `self` and `rhs`.
987    ///
988    /// The midpoint is the average of, or halfway point between, two vectors.
989    /// `a.midpoint(b)` should yield the same result as `a.lerp(b, 0.5)`
990    /// while being slightly cheaper to compute.
991    #[inline]
992    pub fn midpoint(self, rhs: Self) -> Self {
993        (self + rhs) * 0.5
994    }
995
996    /// Returns true if the absolute difference of all elements between `self` and `rhs` is
997    /// less than or equal to `max_abs_diff`.
998    ///
999    /// This can be used to compare if two vectors contain similar elements. It works best when
1000    /// comparing with a known value. The `max_abs_diff` that should be used used depends on
1001    /// the values being compared against.
1002    ///
1003    /// For more see
1004    /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/).
1005    #[inline]
1006    #[must_use]
1007    pub fn abs_diff_eq(self, rhs: Self, max_abs_diff: f64) -> bool {
1008        self.sub(rhs).abs().cmple(Self::splat(max_abs_diff)).all()
1009    }
1010
1011    /// Returns a vector with a length no less than `min` and no more than `max`.
1012    ///
1013    /// # Panics
1014    ///
1015    /// Will panic if `min` is greater than `max`, or if either `min` or `max` is negative, when `glam_assert` is enabled.
1016    #[inline]
1017    #[must_use]
1018    pub fn clamp_length(self, min: f64, max: f64) -> Self {
1019        glam_assert!(0.0 <= min);
1020        glam_assert!(min <= max);
1021        let length_sq = self.length_squared();
1022        if length_sq < min * min {
1023            min * (self / math::sqrt(length_sq))
1024        } else if length_sq > max * max {
1025            max * (self / math::sqrt(length_sq))
1026        } else {
1027            self
1028        }
1029    }
1030
1031    /// Returns a vector with a length no more than `max`.
1032    ///
1033    /// # Panics
1034    ///
1035    /// Will panic if `max` is negative when `glam_assert` is enabled.
1036    #[inline]
1037    #[must_use]
1038    pub fn clamp_length_max(self, max: f64) -> Self {
1039        glam_assert!(0.0 <= max);
1040        let length_sq = self.length_squared();
1041        if length_sq > max * max {
1042            max * (self / math::sqrt(length_sq))
1043        } else {
1044            self
1045        }
1046    }
1047
1048    /// Returns a vector with a length no less than `min`.
1049    ///
1050    /// # Panics
1051    ///
1052    /// Will panic if `min` is negative when `glam_assert` is enabled.
1053    #[inline]
1054    #[must_use]
1055    pub fn clamp_length_min(self, min: f64) -> Self {
1056        glam_assert!(0.0 <= min);
1057        let length_sq = self.length_squared();
1058        if length_sq < min * min {
1059            min * (self / math::sqrt(length_sq))
1060        } else {
1061            self
1062        }
1063    }
1064
1065    /// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding
1066    /// error, yielding a more accurate result than an unfused multiply-add.
1067    ///
1068    /// Using `mul_add` *may* be more performant than an unfused multiply-add if the target
1069    /// architecture has a dedicated fma CPU instruction. However, this is not always true,
1070    /// and will be heavily dependant on designing algorithms with specific target hardware in
1071    /// mind.
1072    #[inline]
1073    #[must_use]
1074    pub fn mul_add(self, a: Self, b: Self) -> Self {
1075        Self::new(
1076            math::mul_add(self.x, a.x, b.x),
1077            math::mul_add(self.y, a.y, b.y),
1078            math::mul_add(self.z, a.z, b.z),
1079        )
1080    }
1081
1082    /// Returns the reflection vector for a given incident vector `self` and surface normal
1083    /// `normal`.
1084    ///
1085    /// `normal` must be normalized.
1086    ///
1087    /// # Panics
1088    ///
1089    /// Will panic if `normal` is not normalized when `glam_assert` is enabled.
1090    #[inline]
1091    #[must_use]
1092    pub fn reflect(self, normal: Self) -> Self {
1093        glam_assert!(normal.is_normalized());
1094        self - 2.0 * self.dot(normal) * normal
1095    }
1096
1097    /// Returns the refraction direction for a given incident vector `self`, surface normal
1098    /// `normal` and ratio of indices of refraction, `eta`. When total internal reflection occurs,
1099    /// a zero vector will be returned.
1100    ///
1101    /// `self` and `normal` must be normalized.
1102    ///
1103    /// # Panics
1104    ///
1105    /// Will panic if `self` or `normal` is not normalized when `glam_assert` is enabled.
1106    #[inline]
1107    #[must_use]
1108    pub fn refract(self, normal: Self, eta: f64) -> Self {
1109        glam_assert!(self.is_normalized());
1110        glam_assert!(normal.is_normalized());
1111        let n_dot_i = normal.dot(self);
1112        let k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
1113        if k >= 0.0 {
1114            eta * self - (eta * n_dot_i + math::sqrt(k)) * normal
1115        } else {
1116            Self::ZERO
1117        }
1118    }
1119
1120    /// Returns the angle (in radians) between two vectors in the range `[0, +Ï€]`.
1121    ///
1122    /// The inputs do not need to be unit vectors however they must be non-zero.
1123    #[inline]
1124    #[must_use]
1125    pub fn angle_between(self, rhs: Self) -> f64 {
1126        math::acos_approx(
1127            self.dot(rhs)
1128                .div(math::sqrt(self.length_squared().mul(rhs.length_squared()))),
1129        )
1130    }
1131
1132    /// Rotates around the x axis by `angle` (in radians).
1133    #[inline]
1134    #[must_use]
1135    pub fn rotate_x(self, angle: f64) -> Self {
1136        let (sina, cosa) = math::sin_cos(angle);
1137        Self::new(
1138            self.x,
1139            self.y * cosa - self.z * sina,
1140            self.y * sina + self.z * cosa,
1141        )
1142    }
1143
1144    /// Rotates around the y axis by `angle` (in radians).
1145    #[inline]
1146    #[must_use]
1147    pub fn rotate_y(self, angle: f64) -> Self {
1148        let (sina, cosa) = math::sin_cos(angle);
1149        Self::new(
1150            self.x * cosa + self.z * sina,
1151            self.y,
1152            self.x * -sina + self.z * cosa,
1153        )
1154    }
1155
1156    /// Rotates around the z axis by `angle` (in radians).
1157    #[inline]
1158    #[must_use]
1159    pub fn rotate_z(self, angle: f64) -> Self {
1160        let (sina, cosa) = math::sin_cos(angle);
1161        Self::new(
1162            self.x * cosa - self.y * sina,
1163            self.x * sina + self.y * cosa,
1164            self.z,
1165        )
1166    }
1167
1168    /// Rotates around `axis` by `angle` (in radians).
1169    ///
1170    /// The axis must be a unit vector.
1171    ///
1172    /// # Panics
1173    ///
1174    /// Will panic if `axis` is not normalized when `glam_assert` is enabled.
1175    #[inline]
1176    #[must_use]
1177    pub fn rotate_axis(self, axis: Self, angle: f64) -> Self {
1178        DQuat::from_axis_angle(axis, angle) * self
1179    }
1180
1181    /// Rotates towards `rhs` up to `max_angle` (in radians).
1182    ///
1183    /// When `max_angle` is `0.0`, the result will be equal to `self`. When `max_angle` is equal to
1184    /// `self.angle_between(rhs)`, the result will be parallel to `rhs`. If `max_angle` is negative,
1185    /// rotates towards the exact opposite of `rhs`. Will not go past the target.
1186    #[inline]
1187    #[must_use]
1188    pub fn rotate_towards(self, rhs: Self, max_angle: f64) -> Self {
1189        let angle_between = self.angle_between(rhs);
1190        // When `max_angle < 0`, rotate no further than `PI` radians away
1191        let angle = max_angle.clamp(angle_between - core::f64::consts::PI, angle_between);
1192        let axis = self
1193            .cross(rhs)
1194            .try_normalize()
1195            .unwrap_or_else(|| self.any_orthogonal_vector().normalize());
1196        DQuat::from_axis_angle(axis, angle) * self
1197    }
1198
1199    /// Returns some vector that is orthogonal to the given one.
1200    ///
1201    /// The input vector must be finite and non-zero.
1202    ///
1203    /// The output vector is not necessarily unit length. For that use
1204    /// [`Self::any_orthonormal_vector()`] instead.
1205    #[inline]
1206    #[must_use]
1207    pub fn any_orthogonal_vector(self) -> Self {
1208        // This can probably be optimized
1209        if math::abs(self.x) > math::abs(self.y) {
1210            Self::new(-self.z, 0.0, self.x) // self.cross(Self::Y)
1211        } else {
1212            Self::new(0.0, self.z, -self.y) // self.cross(Self::X)
1213        }
1214    }
1215
1216    /// Returns any unit vector that is orthogonal to the given one.
1217    ///
1218    /// The input vector must be unit length.
1219    ///
1220    /// # Panics
1221    ///
1222    /// Will panic if `self` is not normalized when `glam_assert` is enabled.
1223    #[inline]
1224    #[must_use]
1225    pub fn any_orthonormal_vector(self) -> Self {
1226        glam_assert!(self.is_normalized());
1227        // From https://graphics.pixar.com/library/OrthonormalB/paper.pdf
1228        let sign = math::signum(self.z);
1229        let a = -1.0 / (sign + self.z);
1230        let b = self.x * self.y * a;
1231        Self::new(b, sign + self.y * self.y * a, -self.y)
1232    }
1233
1234    /// Given a unit vector return two other vectors that together form a right-handed orthonormal
1235    /// basis. That is, all three vectors are orthogonal to each other and are normalized.
1236    ///
1237    /// # Panics
1238    ///
1239    /// Will panic if `self` is not normalized when `glam_assert` is enabled.
1240    #[inline]
1241    #[must_use]
1242    pub fn any_orthonormal_pair(self) -> (Self, Self) {
1243        glam_assert!(self.is_normalized());
1244        // From https://graphics.pixar.com/library/OrthonormalB/paper.pdf
1245        let sign = math::signum(self.z);
1246        let a = -1.0 / (sign + self.z);
1247        let b = self.x * self.y * a;
1248        (
1249            Self::new(1.0 + sign * self.x * self.x * a, sign * b, -sign * self.x),
1250            Self::new(b, sign + self.y * self.y * a, -self.y),
1251        )
1252    }
1253
1254    /// Performs a spherical linear interpolation between `self` and `rhs` based on the value `s`.
1255    ///
1256    /// When `s` is `0.0`, the result will be equal to `self`.  When `s` is `1.0`, the result
1257    /// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly
1258    /// extrapolated.
1259    #[inline]
1260    #[must_use]
1261    pub fn slerp(self, rhs: Self, s: f64) -> Self {
1262        let self_length = self.length();
1263        let rhs_length = rhs.length();
1264        // Cosine of the angle between the vectors [-1, 1], or NaN if either vector has a zero length
1265        let dot = self.dot(rhs) / (self_length * rhs_length);
1266        // If dot is close to 1 or -1, or is NaN the calculations for t1 and t2 break down
1267        if math::abs(dot) < 1.0 - 3e-7 {
1268            // Angle between the vectors [0, +Ï€]
1269            let theta = math::acos_approx(dot);
1270            // Sine of the angle between vectors [0, 1]
1271            let sin_theta = math::sin(theta);
1272            let t1 = math::sin(theta * (1. - s));
1273            let t2 = math::sin(theta * s);
1274
1275            // Interpolate vector lengths
1276            let result_length = self_length.lerp(rhs_length, s);
1277            // Scale the vectors to the target length and interpolate them
1278            return (self * (result_length / self_length) * t1
1279                + rhs * (result_length / rhs_length) * t2)
1280                * sin_theta.recip();
1281        }
1282        if dot < 0.0 {
1283            // Vectors are almost parallel in opposing directions
1284
1285            // Create a rotation from self to rhs along some axis
1286            let axis = self.any_orthogonal_vector().normalize();
1287            let rotation = DQuat::from_axis_angle(axis, core::f64::consts::PI * s);
1288            // Interpolate vector lengths
1289            let result_length = self_length.lerp(rhs_length, s);
1290            rotation * self * (result_length / self_length)
1291        } else {
1292            // Vectors are almost parallel in the same direction, or dot was NaN
1293            self.lerp(rhs, s)
1294        }
1295    }
1296
1297    /// Casts all elements of `self` to `f32`.
1298    #[inline]
1299    #[must_use]
1300    pub fn as_vec3(self) -> crate::Vec3 {
1301        crate::Vec3::new(self.x as f32, self.y as f32, self.z as f32)
1302    }
1303
1304    /// Casts all elements of `self` to `f32`.
1305    #[inline]
1306    #[must_use]
1307    pub fn as_vec3a(self) -> crate::Vec3A {
1308        crate::Vec3A::new(self.x as f32, self.y as f32, self.z as f32)
1309    }
1310
1311    /// Casts all elements of `self` to `i8`.
1312    #[cfg(feature = "i8")]
1313    #[inline]
1314    #[must_use]
1315    pub fn as_i8vec3(self) -> crate::I8Vec3 {
1316        crate::I8Vec3::new(self.x as i8, self.y as i8, self.z as i8)
1317    }
1318
1319    /// Casts all elements of `self` to `u8`.
1320    #[cfg(feature = "u8")]
1321    #[inline]
1322    #[must_use]
1323    pub fn as_u8vec3(self) -> crate::U8Vec3 {
1324        crate::U8Vec3::new(self.x as u8, self.y as u8, self.z as u8)
1325    }
1326
1327    /// Casts all elements of `self` to `i16`.
1328    #[cfg(feature = "i16")]
1329    #[inline]
1330    #[must_use]
1331    pub fn as_i16vec3(self) -> crate::I16Vec3 {
1332        crate::I16Vec3::new(self.x as i16, self.y as i16, self.z as i16)
1333    }
1334
1335    /// Casts all elements of `self` to `u16`.
1336    #[cfg(feature = "u16")]
1337    #[inline]
1338    #[must_use]
1339    pub fn as_u16vec3(self) -> crate::U16Vec3 {
1340        crate::U16Vec3::new(self.x as u16, self.y as u16, self.z as u16)
1341    }
1342
1343    /// Casts all elements of `self` to `i32`.
1344    #[cfg(feature = "i32")]
1345    #[inline]
1346    #[must_use]
1347    pub fn as_ivec3(self) -> crate::IVec3 {
1348        crate::IVec3::new(self.x as i32, self.y as i32, self.z as i32)
1349    }
1350
1351    /// Casts all elements of `self` to `u32`.
1352    #[cfg(feature = "u32")]
1353    #[inline]
1354    #[must_use]
1355    pub fn as_uvec3(self) -> crate::UVec3 {
1356        crate::UVec3::new(self.x as u32, self.y as u32, self.z as u32)
1357    }
1358
1359    /// Casts all elements of `self` to `i64`.
1360    #[cfg(feature = "i64")]
1361    #[inline]
1362    #[must_use]
1363    pub fn as_i64vec3(self) -> crate::I64Vec3 {
1364        crate::I64Vec3::new(self.x as i64, self.y as i64, self.z as i64)
1365    }
1366
1367    /// Casts all elements of `self` to `u64`.
1368    #[cfg(feature = "u64")]
1369    #[inline]
1370    #[must_use]
1371    pub fn as_u64vec3(self) -> crate::U64Vec3 {
1372        crate::U64Vec3::new(self.x as u64, self.y as u64, self.z as u64)
1373    }
1374
1375    /// Casts all elements of `self` to `isize`.
1376    #[cfg(feature = "isize")]
1377    #[inline]
1378    #[must_use]
1379    pub fn as_isizevec3(self) -> crate::ISizeVec3 {
1380        crate::ISizeVec3::new(self.x as isize, self.y as isize, self.z as isize)
1381    }
1382
1383    /// Casts all elements of `self` to `usize`.
1384    #[cfg(feature = "usize")]
1385    #[inline]
1386    #[must_use]
1387    pub fn as_usizevec3(self) -> crate::USizeVec3 {
1388        crate::USizeVec3::new(self.x as usize, self.y as usize, self.z as usize)
1389    }
1390}
1391
1392impl Default for DVec3 {
1393    #[inline(always)]
1394    fn default() -> Self {
1395        Self::ZERO
1396    }
1397}
1398
1399impl Div for DVec3 {
1400    type Output = Self;
1401    #[inline]
1402    fn div(self, rhs: Self) -> Self {
1403        Self {
1404            x: self.x.div(rhs.x),
1405            y: self.y.div(rhs.y),
1406            z: self.z.div(rhs.z),
1407        }
1408    }
1409}
1410
1411impl Div<&Self> for DVec3 {
1412    type Output = Self;
1413    #[inline]
1414    fn div(self, rhs: &Self) -> Self {
1415        self.div(*rhs)
1416    }
1417}
1418
1419impl Div<&DVec3> for &DVec3 {
1420    type Output = DVec3;
1421    #[inline]
1422    fn div(self, rhs: &DVec3) -> DVec3 {
1423        (*self).div(*rhs)
1424    }
1425}
1426
1427impl Div<DVec3> for &DVec3 {
1428    type Output = DVec3;
1429    #[inline]
1430    fn div(self, rhs: DVec3) -> DVec3 {
1431        (*self).div(rhs)
1432    }
1433}
1434
1435impl DivAssign for DVec3 {
1436    #[inline]
1437    fn div_assign(&mut self, rhs: Self) {
1438        self.x.div_assign(rhs.x);
1439        self.y.div_assign(rhs.y);
1440        self.z.div_assign(rhs.z);
1441    }
1442}
1443
1444impl DivAssign<&Self> for DVec3 {
1445    #[inline]
1446    fn div_assign(&mut self, rhs: &Self) {
1447        self.div_assign(*rhs);
1448    }
1449}
1450
1451impl Div<f64> for DVec3 {
1452    type Output = Self;
1453    #[inline]
1454    fn div(self, rhs: f64) -> Self {
1455        Self {
1456            x: self.x.div(rhs),
1457            y: self.y.div(rhs),
1458            z: self.z.div(rhs),
1459        }
1460    }
1461}
1462
1463impl Div<&f64> for DVec3 {
1464    type Output = Self;
1465    #[inline]
1466    fn div(self, rhs: &f64) -> Self {
1467        self.div(*rhs)
1468    }
1469}
1470
1471impl Div<&f64> for &DVec3 {
1472    type Output = DVec3;
1473    #[inline]
1474    fn div(self, rhs: &f64) -> DVec3 {
1475        (*self).div(*rhs)
1476    }
1477}
1478
1479impl Div<f64> for &DVec3 {
1480    type Output = DVec3;
1481    #[inline]
1482    fn div(self, rhs: f64) -> DVec3 {
1483        (*self).div(rhs)
1484    }
1485}
1486
1487impl DivAssign<f64> for DVec3 {
1488    #[inline]
1489    fn div_assign(&mut self, rhs: f64) {
1490        self.x.div_assign(rhs);
1491        self.y.div_assign(rhs);
1492        self.z.div_assign(rhs);
1493    }
1494}
1495
1496impl DivAssign<&f64> for DVec3 {
1497    #[inline]
1498    fn div_assign(&mut self, rhs: &f64) {
1499        self.div_assign(*rhs);
1500    }
1501}
1502
1503impl Div<DVec3> for f64 {
1504    type Output = DVec3;
1505    #[inline]
1506    fn div(self, rhs: DVec3) -> DVec3 {
1507        DVec3 {
1508            x: self.div(rhs.x),
1509            y: self.div(rhs.y),
1510            z: self.div(rhs.z),
1511        }
1512    }
1513}
1514
1515impl Div<&DVec3> for f64 {
1516    type Output = DVec3;
1517    #[inline]
1518    fn div(self, rhs: &DVec3) -> DVec3 {
1519        self.div(*rhs)
1520    }
1521}
1522
1523impl Div<&DVec3> for &f64 {
1524    type Output = DVec3;
1525    #[inline]
1526    fn div(self, rhs: &DVec3) -> DVec3 {
1527        (*self).div(*rhs)
1528    }
1529}
1530
1531impl Div<DVec3> for &f64 {
1532    type Output = DVec3;
1533    #[inline]
1534    fn div(self, rhs: DVec3) -> DVec3 {
1535        (*self).div(rhs)
1536    }
1537}
1538
1539impl Mul for DVec3 {
1540    type Output = Self;
1541    #[inline]
1542    fn mul(self, rhs: Self) -> Self {
1543        Self {
1544            x: self.x.mul(rhs.x),
1545            y: self.y.mul(rhs.y),
1546            z: self.z.mul(rhs.z),
1547        }
1548    }
1549}
1550
1551impl Mul<&Self> for DVec3 {
1552    type Output = Self;
1553    #[inline]
1554    fn mul(self, rhs: &Self) -> Self {
1555        self.mul(*rhs)
1556    }
1557}
1558
1559impl Mul<&DVec3> for &DVec3 {
1560    type Output = DVec3;
1561    #[inline]
1562    fn mul(self, rhs: &DVec3) -> DVec3 {
1563        (*self).mul(*rhs)
1564    }
1565}
1566
1567impl Mul<DVec3> for &DVec3 {
1568    type Output = DVec3;
1569    #[inline]
1570    fn mul(self, rhs: DVec3) -> DVec3 {
1571        (*self).mul(rhs)
1572    }
1573}
1574
1575impl MulAssign for DVec3 {
1576    #[inline]
1577    fn mul_assign(&mut self, rhs: Self) {
1578        self.x.mul_assign(rhs.x);
1579        self.y.mul_assign(rhs.y);
1580        self.z.mul_assign(rhs.z);
1581    }
1582}
1583
1584impl MulAssign<&Self> for DVec3 {
1585    #[inline]
1586    fn mul_assign(&mut self, rhs: &Self) {
1587        self.mul_assign(*rhs);
1588    }
1589}
1590
1591impl Mul<f64> for DVec3 {
1592    type Output = Self;
1593    #[inline]
1594    fn mul(self, rhs: f64) -> Self {
1595        Self {
1596            x: self.x.mul(rhs),
1597            y: self.y.mul(rhs),
1598            z: self.z.mul(rhs),
1599        }
1600    }
1601}
1602
1603impl Mul<&f64> for DVec3 {
1604    type Output = Self;
1605    #[inline]
1606    fn mul(self, rhs: &f64) -> Self {
1607        self.mul(*rhs)
1608    }
1609}
1610
1611impl Mul<&f64> for &DVec3 {
1612    type Output = DVec3;
1613    #[inline]
1614    fn mul(self, rhs: &f64) -> DVec3 {
1615        (*self).mul(*rhs)
1616    }
1617}
1618
1619impl Mul<f64> for &DVec3 {
1620    type Output = DVec3;
1621    #[inline]
1622    fn mul(self, rhs: f64) -> DVec3 {
1623        (*self).mul(rhs)
1624    }
1625}
1626
1627impl MulAssign<f64> for DVec3 {
1628    #[inline]
1629    fn mul_assign(&mut self, rhs: f64) {
1630        self.x.mul_assign(rhs);
1631        self.y.mul_assign(rhs);
1632        self.z.mul_assign(rhs);
1633    }
1634}
1635
1636impl MulAssign<&f64> for DVec3 {
1637    #[inline]
1638    fn mul_assign(&mut self, rhs: &f64) {
1639        self.mul_assign(*rhs);
1640    }
1641}
1642
1643impl Mul<DVec3> for f64 {
1644    type Output = DVec3;
1645    #[inline]
1646    fn mul(self, rhs: DVec3) -> DVec3 {
1647        DVec3 {
1648            x: self.mul(rhs.x),
1649            y: self.mul(rhs.y),
1650            z: self.mul(rhs.z),
1651        }
1652    }
1653}
1654
1655impl Mul<&DVec3> for f64 {
1656    type Output = DVec3;
1657    #[inline]
1658    fn mul(self, rhs: &DVec3) -> DVec3 {
1659        self.mul(*rhs)
1660    }
1661}
1662
1663impl Mul<&DVec3> for &f64 {
1664    type Output = DVec3;
1665    #[inline]
1666    fn mul(self, rhs: &DVec3) -> DVec3 {
1667        (*self).mul(*rhs)
1668    }
1669}
1670
1671impl Mul<DVec3> for &f64 {
1672    type Output = DVec3;
1673    #[inline]
1674    fn mul(self, rhs: DVec3) -> DVec3 {
1675        (*self).mul(rhs)
1676    }
1677}
1678
1679impl Add for DVec3 {
1680    type Output = Self;
1681    #[inline]
1682    fn add(self, rhs: Self) -> Self {
1683        Self {
1684            x: self.x.add(rhs.x),
1685            y: self.y.add(rhs.y),
1686            z: self.z.add(rhs.z),
1687        }
1688    }
1689}
1690
1691impl Add<&Self> for DVec3 {
1692    type Output = Self;
1693    #[inline]
1694    fn add(self, rhs: &Self) -> Self {
1695        self.add(*rhs)
1696    }
1697}
1698
1699impl Add<&DVec3> for &DVec3 {
1700    type Output = DVec3;
1701    #[inline]
1702    fn add(self, rhs: &DVec3) -> DVec3 {
1703        (*self).add(*rhs)
1704    }
1705}
1706
1707impl Add<DVec3> for &DVec3 {
1708    type Output = DVec3;
1709    #[inline]
1710    fn add(self, rhs: DVec3) -> DVec3 {
1711        (*self).add(rhs)
1712    }
1713}
1714
1715impl AddAssign for DVec3 {
1716    #[inline]
1717    fn add_assign(&mut self, rhs: Self) {
1718        self.x.add_assign(rhs.x);
1719        self.y.add_assign(rhs.y);
1720        self.z.add_assign(rhs.z);
1721    }
1722}
1723
1724impl AddAssign<&Self> for DVec3 {
1725    #[inline]
1726    fn add_assign(&mut self, rhs: &Self) {
1727        self.add_assign(*rhs);
1728    }
1729}
1730
1731impl Add<f64> for DVec3 {
1732    type Output = Self;
1733    #[inline]
1734    fn add(self, rhs: f64) -> Self {
1735        Self {
1736            x: self.x.add(rhs),
1737            y: self.y.add(rhs),
1738            z: self.z.add(rhs),
1739        }
1740    }
1741}
1742
1743impl Add<&f64> for DVec3 {
1744    type Output = Self;
1745    #[inline]
1746    fn add(self, rhs: &f64) -> Self {
1747        self.add(*rhs)
1748    }
1749}
1750
1751impl Add<&f64> for &DVec3 {
1752    type Output = DVec3;
1753    #[inline]
1754    fn add(self, rhs: &f64) -> DVec3 {
1755        (*self).add(*rhs)
1756    }
1757}
1758
1759impl Add<f64> for &DVec3 {
1760    type Output = DVec3;
1761    #[inline]
1762    fn add(self, rhs: f64) -> DVec3 {
1763        (*self).add(rhs)
1764    }
1765}
1766
1767impl AddAssign<f64> for DVec3 {
1768    #[inline]
1769    fn add_assign(&mut self, rhs: f64) {
1770        self.x.add_assign(rhs);
1771        self.y.add_assign(rhs);
1772        self.z.add_assign(rhs);
1773    }
1774}
1775
1776impl AddAssign<&f64> for DVec3 {
1777    #[inline]
1778    fn add_assign(&mut self, rhs: &f64) {
1779        self.add_assign(*rhs);
1780    }
1781}
1782
1783impl Add<DVec3> for f64 {
1784    type Output = DVec3;
1785    #[inline]
1786    fn add(self, rhs: DVec3) -> DVec3 {
1787        DVec3 {
1788            x: self.add(rhs.x),
1789            y: self.add(rhs.y),
1790            z: self.add(rhs.z),
1791        }
1792    }
1793}
1794
1795impl Add<&DVec3> for f64 {
1796    type Output = DVec3;
1797    #[inline]
1798    fn add(self, rhs: &DVec3) -> DVec3 {
1799        self.add(*rhs)
1800    }
1801}
1802
1803impl Add<&DVec3> for &f64 {
1804    type Output = DVec3;
1805    #[inline]
1806    fn add(self, rhs: &DVec3) -> DVec3 {
1807        (*self).add(*rhs)
1808    }
1809}
1810
1811impl Add<DVec3> for &f64 {
1812    type Output = DVec3;
1813    #[inline]
1814    fn add(self, rhs: DVec3) -> DVec3 {
1815        (*self).add(rhs)
1816    }
1817}
1818
1819impl Sub for DVec3 {
1820    type Output = Self;
1821    #[inline]
1822    fn sub(self, rhs: Self) -> Self {
1823        Self {
1824            x: self.x.sub(rhs.x),
1825            y: self.y.sub(rhs.y),
1826            z: self.z.sub(rhs.z),
1827        }
1828    }
1829}
1830
1831impl Sub<&Self> for DVec3 {
1832    type Output = Self;
1833    #[inline]
1834    fn sub(self, rhs: &Self) -> Self {
1835        self.sub(*rhs)
1836    }
1837}
1838
1839impl Sub<&DVec3> for &DVec3 {
1840    type Output = DVec3;
1841    #[inline]
1842    fn sub(self, rhs: &DVec3) -> DVec3 {
1843        (*self).sub(*rhs)
1844    }
1845}
1846
1847impl Sub<DVec3> for &DVec3 {
1848    type Output = DVec3;
1849    #[inline]
1850    fn sub(self, rhs: DVec3) -> DVec3 {
1851        (*self).sub(rhs)
1852    }
1853}
1854
1855impl SubAssign for DVec3 {
1856    #[inline]
1857    fn sub_assign(&mut self, rhs: Self) {
1858        self.x.sub_assign(rhs.x);
1859        self.y.sub_assign(rhs.y);
1860        self.z.sub_assign(rhs.z);
1861    }
1862}
1863
1864impl SubAssign<&Self> for DVec3 {
1865    #[inline]
1866    fn sub_assign(&mut self, rhs: &Self) {
1867        self.sub_assign(*rhs);
1868    }
1869}
1870
1871impl Sub<f64> for DVec3 {
1872    type Output = Self;
1873    #[inline]
1874    fn sub(self, rhs: f64) -> Self {
1875        Self {
1876            x: self.x.sub(rhs),
1877            y: self.y.sub(rhs),
1878            z: self.z.sub(rhs),
1879        }
1880    }
1881}
1882
1883impl Sub<&f64> for DVec3 {
1884    type Output = Self;
1885    #[inline]
1886    fn sub(self, rhs: &f64) -> Self {
1887        self.sub(*rhs)
1888    }
1889}
1890
1891impl Sub<&f64> for &DVec3 {
1892    type Output = DVec3;
1893    #[inline]
1894    fn sub(self, rhs: &f64) -> DVec3 {
1895        (*self).sub(*rhs)
1896    }
1897}
1898
1899impl Sub<f64> for &DVec3 {
1900    type Output = DVec3;
1901    #[inline]
1902    fn sub(self, rhs: f64) -> DVec3 {
1903        (*self).sub(rhs)
1904    }
1905}
1906
1907impl SubAssign<f64> for DVec3 {
1908    #[inline]
1909    fn sub_assign(&mut self, rhs: f64) {
1910        self.x.sub_assign(rhs);
1911        self.y.sub_assign(rhs);
1912        self.z.sub_assign(rhs);
1913    }
1914}
1915
1916impl SubAssign<&f64> for DVec3 {
1917    #[inline]
1918    fn sub_assign(&mut self, rhs: &f64) {
1919        self.sub_assign(*rhs);
1920    }
1921}
1922
1923impl Sub<DVec3> for f64 {
1924    type Output = DVec3;
1925    #[inline]
1926    fn sub(self, rhs: DVec3) -> DVec3 {
1927        DVec3 {
1928            x: self.sub(rhs.x),
1929            y: self.sub(rhs.y),
1930            z: self.sub(rhs.z),
1931        }
1932    }
1933}
1934
1935impl Sub<&DVec3> for f64 {
1936    type Output = DVec3;
1937    #[inline]
1938    fn sub(self, rhs: &DVec3) -> DVec3 {
1939        self.sub(*rhs)
1940    }
1941}
1942
1943impl Sub<&DVec3> for &f64 {
1944    type Output = DVec3;
1945    #[inline]
1946    fn sub(self, rhs: &DVec3) -> DVec3 {
1947        (*self).sub(*rhs)
1948    }
1949}
1950
1951impl Sub<DVec3> for &f64 {
1952    type Output = DVec3;
1953    #[inline]
1954    fn sub(self, rhs: DVec3) -> DVec3 {
1955        (*self).sub(rhs)
1956    }
1957}
1958
1959impl Rem for DVec3 {
1960    type Output = Self;
1961    #[inline]
1962    fn rem(self, rhs: Self) -> Self {
1963        Self {
1964            x: self.x.rem(rhs.x),
1965            y: self.y.rem(rhs.y),
1966            z: self.z.rem(rhs.z),
1967        }
1968    }
1969}
1970
1971impl Rem<&Self> for DVec3 {
1972    type Output = Self;
1973    #[inline]
1974    fn rem(self, rhs: &Self) -> Self {
1975        self.rem(*rhs)
1976    }
1977}
1978
1979impl Rem<&DVec3> for &DVec3 {
1980    type Output = DVec3;
1981    #[inline]
1982    fn rem(self, rhs: &DVec3) -> DVec3 {
1983        (*self).rem(*rhs)
1984    }
1985}
1986
1987impl Rem<DVec3> for &DVec3 {
1988    type Output = DVec3;
1989    #[inline]
1990    fn rem(self, rhs: DVec3) -> DVec3 {
1991        (*self).rem(rhs)
1992    }
1993}
1994
1995impl RemAssign for DVec3 {
1996    #[inline]
1997    fn rem_assign(&mut self, rhs: Self) {
1998        self.x.rem_assign(rhs.x);
1999        self.y.rem_assign(rhs.y);
2000        self.z.rem_assign(rhs.z);
2001    }
2002}
2003
2004impl RemAssign<&Self> for DVec3 {
2005    #[inline]
2006    fn rem_assign(&mut self, rhs: &Self) {
2007        self.rem_assign(*rhs);
2008    }
2009}
2010
2011impl Rem<f64> for DVec3 {
2012    type Output = Self;
2013    #[inline]
2014    fn rem(self, rhs: f64) -> Self {
2015        Self {
2016            x: self.x.rem(rhs),
2017            y: self.y.rem(rhs),
2018            z: self.z.rem(rhs),
2019        }
2020    }
2021}
2022
2023impl Rem<&f64> for DVec3 {
2024    type Output = Self;
2025    #[inline]
2026    fn rem(self, rhs: &f64) -> Self {
2027        self.rem(*rhs)
2028    }
2029}
2030
2031impl Rem<&f64> for &DVec3 {
2032    type Output = DVec3;
2033    #[inline]
2034    fn rem(self, rhs: &f64) -> DVec3 {
2035        (*self).rem(*rhs)
2036    }
2037}
2038
2039impl Rem<f64> for &DVec3 {
2040    type Output = DVec3;
2041    #[inline]
2042    fn rem(self, rhs: f64) -> DVec3 {
2043        (*self).rem(rhs)
2044    }
2045}
2046
2047impl RemAssign<f64> for DVec3 {
2048    #[inline]
2049    fn rem_assign(&mut self, rhs: f64) {
2050        self.x.rem_assign(rhs);
2051        self.y.rem_assign(rhs);
2052        self.z.rem_assign(rhs);
2053    }
2054}
2055
2056impl RemAssign<&f64> for DVec3 {
2057    #[inline]
2058    fn rem_assign(&mut self, rhs: &f64) {
2059        self.rem_assign(*rhs);
2060    }
2061}
2062
2063impl Rem<DVec3> for f64 {
2064    type Output = DVec3;
2065    #[inline]
2066    fn rem(self, rhs: DVec3) -> DVec3 {
2067        DVec3 {
2068            x: self.rem(rhs.x),
2069            y: self.rem(rhs.y),
2070            z: self.rem(rhs.z),
2071        }
2072    }
2073}
2074
2075impl Rem<&DVec3> for f64 {
2076    type Output = DVec3;
2077    #[inline]
2078    fn rem(self, rhs: &DVec3) -> DVec3 {
2079        self.rem(*rhs)
2080    }
2081}
2082
2083impl Rem<&DVec3> for &f64 {
2084    type Output = DVec3;
2085    #[inline]
2086    fn rem(self, rhs: &DVec3) -> DVec3 {
2087        (*self).rem(*rhs)
2088    }
2089}
2090
2091impl Rem<DVec3> for &f64 {
2092    type Output = DVec3;
2093    #[inline]
2094    fn rem(self, rhs: DVec3) -> DVec3 {
2095        (*self).rem(rhs)
2096    }
2097}
2098
2099impl AsRef<[f64; 3]> for DVec3 {
2100    #[inline]
2101    fn as_ref(&self) -> &[f64; 3] {
2102        unsafe { &*(self as *const Self as *const [f64; 3]) }
2103    }
2104}
2105
2106impl AsMut<[f64; 3]> for DVec3 {
2107    #[inline]
2108    fn as_mut(&mut self) -> &mut [f64; 3] {
2109        unsafe { &mut *(self as *mut Self as *mut [f64; 3]) }
2110    }
2111}
2112
2113impl Sum for DVec3 {
2114    #[inline]
2115    fn sum<I>(iter: I) -> Self
2116    where
2117        I: Iterator<Item = Self>,
2118    {
2119        iter.fold(Self::ZERO, Self::add)
2120    }
2121}
2122
2123impl<'a> Sum<&'a Self> for DVec3 {
2124    #[inline]
2125    fn sum<I>(iter: I) -> Self
2126    where
2127        I: Iterator<Item = &'a Self>,
2128    {
2129        iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
2130    }
2131}
2132
2133impl Product for DVec3 {
2134    #[inline]
2135    fn product<I>(iter: I) -> Self
2136    where
2137        I: Iterator<Item = Self>,
2138    {
2139        iter.fold(Self::ONE, Self::mul)
2140    }
2141}
2142
2143impl<'a> Product<&'a Self> for DVec3 {
2144    #[inline]
2145    fn product<I>(iter: I) -> Self
2146    where
2147        I: Iterator<Item = &'a Self>,
2148    {
2149        iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
2150    }
2151}
2152
2153impl Neg for DVec3 {
2154    type Output = Self;
2155    #[inline]
2156    fn neg(self) -> Self {
2157        Self {
2158            x: self.x.neg(),
2159            y: self.y.neg(),
2160            z: self.z.neg(),
2161        }
2162    }
2163}
2164
2165impl Neg for &DVec3 {
2166    type Output = DVec3;
2167    #[inline]
2168    fn neg(self) -> DVec3 {
2169        (*self).neg()
2170    }
2171}
2172
2173impl Index<usize> for DVec3 {
2174    type Output = f64;
2175    #[inline]
2176    fn index(&self, index: usize) -> &Self::Output {
2177        match index {
2178            0 => &self.x,
2179            1 => &self.y,
2180            2 => &self.z,
2181            _ => panic!("index out of bounds"),
2182        }
2183    }
2184}
2185
2186impl IndexMut<usize> for DVec3 {
2187    #[inline]
2188    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
2189        match index {
2190            0 => &mut self.x,
2191            1 => &mut self.y,
2192            2 => &mut self.z,
2193            _ => panic!("index out of bounds"),
2194        }
2195    }
2196}
2197
2198impl fmt::Display for DVec3 {
2199    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2200        if let Some(p) = f.precision() {
2201            write!(f, "[{:.*}, {:.*}, {:.*}]", p, self.x, p, self.y, p, self.z)
2202        } else {
2203            write!(f, "[{}, {}, {}]", self.x, self.y, self.z)
2204        }
2205    }
2206}
2207
2208impl fmt::Debug for DVec3 {
2209    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
2210        fmt.debug_tuple(stringify!(DVec3))
2211            .field(&self.x)
2212            .field(&self.y)
2213            .field(&self.z)
2214            .finish()
2215    }
2216}
2217
2218impl From<[f64; 3]> for DVec3 {
2219    #[inline]
2220    fn from(a: [f64; 3]) -> Self {
2221        Self::new(a[0], a[1], a[2])
2222    }
2223}
2224
2225impl From<DVec3> for [f64; 3] {
2226    #[inline]
2227    fn from(v: DVec3) -> Self {
2228        [v.x, v.y, v.z]
2229    }
2230}
2231
2232impl From<(f64, f64, f64)> for DVec3 {
2233    #[inline]
2234    fn from(t: (f64, f64, f64)) -> Self {
2235        Self::new(t.0, t.1, t.2)
2236    }
2237}
2238
2239impl From<DVec3> for (f64, f64, f64) {
2240    #[inline]
2241    fn from(v: DVec3) -> Self {
2242        (v.x, v.y, v.z)
2243    }
2244}
2245
2246impl From<(DVec2, f64)> for DVec3 {
2247    #[inline]
2248    fn from((v, z): (DVec2, f64)) -> Self {
2249        Self::new(v.x, v.y, z)
2250    }
2251}
2252
2253impl From<Vec3> for DVec3 {
2254    #[inline]
2255    fn from(v: Vec3) -> Self {
2256        Self::new(f64::from(v.x), f64::from(v.y), f64::from(v.z))
2257    }
2258}
2259
2260#[cfg(feature = "i32")]
2261impl From<IVec3> for DVec3 {
2262    #[inline]
2263    fn from(v: IVec3) -> Self {
2264        Self::new(f64::from(v.x), f64::from(v.y), f64::from(v.z))
2265    }
2266}
2267
2268#[cfg(feature = "u32")]
2269impl From<UVec3> for DVec3 {
2270    #[inline]
2271    fn from(v: UVec3) -> Self {
2272        Self::new(f64::from(v.x), f64::from(v.y), f64::from(v.z))
2273    }
2274}
2275
2276impl From<BVec3> for DVec3 {
2277    #[inline]
2278    fn from(v: BVec3) -> Self {
2279        Self::new(f64::from(v.x), f64::from(v.y), f64::from(v.z))
2280    }
2281}
2282
2283impl From<BVec3A> for DVec3 {
2284    #[inline]
2285    fn from(v: BVec3A) -> Self {
2286        let bool_array: [bool; 3] = v.into();
2287        Self::new(
2288            f64::from(bool_array[0]),
2289            f64::from(bool_array[1]),
2290            f64::from(bool_array[2]),
2291        )
2292    }
2293}