• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Generated from vec.rs.tera template. Edit the template, not the generated file.
2 
3 use crate::{f32::math, wasm32::*, BVec3, BVec3A, FloatExt, Quat, Vec2, Vec3, Vec4};
4 
5 use core::fmt;
6 use core::iter::{Product, Sum};
7 use core::{f32, ops::*};
8 
9 use core::arch::wasm32::*;
10 
11 /// Creates a 3-dimensional vector.
12 #[inline(always)]
13 #[must_use]
vec3a(x: f32, y: f32, z: f32) -> Vec3A14 pub const fn vec3a(x: f32, y: f32, z: f32) -> Vec3A {
15     Vec3A::new(x, y, z)
16 }
17 
18 /// A 3-dimensional vector.
19 ///
20 /// SIMD vector types are used for storage on supported platforms for better
21 /// performance than the [`Vec3`] type.
22 ///
23 /// It is possible to convert between [`Vec3`] and [`Vec3A`] types using [`From`]
24 /// or [`Into`] trait implementations.
25 ///
26 /// This type is 16 byte aligned.
27 #[derive(Clone, Copy)]
28 #[repr(transparent)]
29 pub struct Vec3A(pub(crate) v128);
30 
31 impl Vec3A {
32     /// All zeroes.
33     pub const ZERO: Self = Self::splat(0.0);
34 
35     /// All ones.
36     pub const ONE: Self = Self::splat(1.0);
37 
38     /// All negative ones.
39     pub const NEG_ONE: Self = Self::splat(-1.0);
40 
41     /// All `f32::MIN`.
42     pub const MIN: Self = Self::splat(f32::MIN);
43 
44     /// All `f32::MAX`.
45     pub const MAX: Self = Self::splat(f32::MAX);
46 
47     /// All `f32::NAN`.
48     pub const NAN: Self = Self::splat(f32::NAN);
49 
50     /// All `f32::INFINITY`.
51     pub const INFINITY: Self = Self::splat(f32::INFINITY);
52 
53     /// All `f32::NEG_INFINITY`.
54     pub const NEG_INFINITY: Self = Self::splat(f32::NEG_INFINITY);
55 
56     /// A unit vector pointing along the positive X axis.
57     pub const X: Self = Self::new(1.0, 0.0, 0.0);
58 
59     /// A unit vector pointing along the positive Y axis.
60     pub const Y: Self = Self::new(0.0, 1.0, 0.0);
61 
62     /// A unit vector pointing along the positive Z axis.
63     pub const Z: Self = Self::new(0.0, 0.0, 1.0);
64 
65     /// A unit vector pointing along the negative X axis.
66     pub const NEG_X: Self = Self::new(-1.0, 0.0, 0.0);
67 
68     /// A unit vector pointing along the negative Y axis.
69     pub const NEG_Y: Self = Self::new(0.0, -1.0, 0.0);
70 
71     /// A unit vector pointing along the negative Z axis.
72     pub const NEG_Z: Self = Self::new(0.0, 0.0, -1.0);
73 
74     /// The unit axes.
75     pub const AXES: [Self; 3] = [Self::X, Self::Y, Self::Z];
76 
77     /// Creates a new vector.
78     #[inline(always)]
79     #[must_use]
new(x: f32, y: f32, z: f32) -> Self80     pub const fn new(x: f32, y: f32, z: f32) -> Self {
81         Self(f32x4(x, y, z, z))
82     }
83 
84     /// Creates a vector with all elements set to `v`.
85     #[inline]
86     #[must_use]
splat(v: f32) -> Self87     pub const fn splat(v: f32) -> Self {
88         Self(f32x4(v, v, v, v))
89     }
90 
91     /// Returns a vector containing each element of `self` modified by a mapping function `f`.
92     #[inline]
93     #[must_use]
map<F>(self, f: F) -> Self where F: Fn(f32) -> f32,94     pub fn map<F>(self, f: F) -> Self
95     where
96         F: Fn(f32) -> f32,
97     {
98         Self::new(f(self.x), f(self.y), f(self.z))
99     }
100 
101     /// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use
102     /// for each element of `self`.
103     ///
104     /// A true element in the mask uses the corresponding element from `if_true`, and false
105     /// uses the element from `if_false`.
106     #[inline]
107     #[must_use]
select(mask: BVec3A, if_true: Self, if_false: Self) -> Self108     pub fn select(mask: BVec3A, if_true: Self, if_false: Self) -> Self {
109         Self(v128_bitselect(if_true.0, if_false.0, mask.0))
110     }
111 
112     /// Creates a new vector from an array.
113     #[inline]
114     #[must_use]
from_array(a: [f32; 3]) -> Self115     pub const fn from_array(a: [f32; 3]) -> Self {
116         Self::new(a[0], a[1], a[2])
117     }
118 
119     /// `[x, y, z]`
120     #[inline]
121     #[must_use]
to_array(&self) -> [f32; 3]122     pub const fn to_array(&self) -> [f32; 3] {
123         unsafe { *(self as *const Vec3A as *const [f32; 3]) }
124     }
125 
126     /// Creates a vector from the first 3 values in `slice`.
127     ///
128     /// # Panics
129     ///
130     /// Panics if `slice` is less than 3 elements long.
131     #[inline]
132     #[must_use]
from_slice(slice: &[f32]) -> Self133     pub const fn from_slice(slice: &[f32]) -> Self {
134         assert!(slice.len() >= 3);
135         Self::new(slice[0], slice[1], slice[2])
136     }
137 
138     /// Writes the elements of `self` to the first 3 elements in `slice`.
139     ///
140     /// # Panics
141     ///
142     /// Panics if `slice` is less than 3 elements long.
143     #[inline]
write_to_slice(self, slice: &mut [f32])144     pub fn write_to_slice(self, slice: &mut [f32]) {
145         slice[..3].copy_from_slice(&self.to_array());
146     }
147 
148     /// Creates a [`Vec3A`] from the `x`, `y` and `z` elements of `self` discarding `w`.
149     ///
150     /// On architectures where SIMD is supported such as SSE2 on `x86_64` this conversion is a noop.
151     #[inline]
152     #[must_use]
from_vec4(v: Vec4) -> Self153     pub fn from_vec4(v: Vec4) -> Self {
154         Self(v.0)
155     }
156 
157     /// Creates a 4D vector from `self` and the given `w` value.
158     #[inline]
159     #[must_use]
extend(self, w: f32) -> Vec4160     pub fn extend(self, w: f32) -> Vec4 {
161         Vec4::new(self.x, self.y, self.z, w)
162     }
163 
164     /// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`.
165     ///
166     /// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()].
167     #[inline]
168     #[must_use]
truncate(self) -> Vec2169     pub fn truncate(self) -> Vec2 {
170         use crate::swizzles::Vec3Swizzles;
171         self.xy()
172     }
173 
174     /// Creates a 3D vector from `self` with the given value of `x`.
175     #[inline]
176     #[must_use]
with_x(mut self, x: f32) -> Self177     pub fn with_x(mut self, x: f32) -> Self {
178         self.x = x;
179         self
180     }
181 
182     /// Creates a 3D vector from `self` with the given value of `y`.
183     #[inline]
184     #[must_use]
with_y(mut self, y: f32) -> Self185     pub fn with_y(mut self, y: f32) -> Self {
186         self.y = y;
187         self
188     }
189 
190     /// Creates a 3D vector from `self` with the given value of `z`.
191     #[inline]
192     #[must_use]
with_z(mut self, z: f32) -> Self193     pub fn with_z(mut self, z: f32) -> Self {
194         self.z = z;
195         self
196     }
197 
198     /// Computes the dot product of `self` and `rhs`.
199     #[inline]
200     #[must_use]
dot(self, rhs: Self) -> f32201     pub fn dot(self, rhs: Self) -> f32 {
202         dot3(self.0, rhs.0)
203     }
204 
205     /// Returns a vector where every component is the dot product of `self` and `rhs`.
206     #[inline]
207     #[must_use]
dot_into_vec(self, rhs: Self) -> Self208     pub fn dot_into_vec(self, rhs: Self) -> Self {
209         Self(dot3_into_v128(self.0, rhs.0))
210     }
211 
212     /// Computes the cross product of `self` and `rhs`.
213     #[inline]
214     #[must_use]
cross(self, rhs: Self) -> Self215     pub fn cross(self, rhs: Self) -> Self {
216         let lhszxy = i32x4_shuffle::<2, 0, 1, 1>(self.0, self.0);
217         let rhszxy = i32x4_shuffle::<2, 0, 1, 1>(rhs.0, rhs.0);
218         let lhszxy_rhs = f32x4_mul(lhszxy, rhs.0);
219         let rhszxy_lhs = f32x4_mul(rhszxy, self.0);
220         let sub = f32x4_sub(lhszxy_rhs, rhszxy_lhs);
221         Self(i32x4_shuffle::<2, 0, 1, 1>(sub, sub))
222     }
223 
224     /// Returns a vector containing the minimum values for each element of `self` and `rhs`.
225     ///
226     /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`.
227     #[inline]
228     #[must_use]
min(self, rhs: Self) -> Self229     pub fn min(self, rhs: Self) -> Self {
230         Self(f32x4_pmin(self.0, rhs.0))
231     }
232 
233     /// Returns a vector containing the maximum values for each element of `self` and `rhs`.
234     ///
235     /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`.
236     #[inline]
237     #[must_use]
max(self, rhs: Self) -> Self238     pub fn max(self, rhs: Self) -> Self {
239         Self(f32x4_pmax(self.0, rhs.0))
240     }
241 
242     /// Component-wise clamping of values, similar to [`f32::clamp`].
243     ///
244     /// Each element in `min` must be less-or-equal to the corresponding element in `max`.
245     ///
246     /// # Panics
247     ///
248     /// Will panic if `min` is greater than `max` when `glam_assert` is enabled.
249     #[inline]
250     #[must_use]
clamp(self, min: Self, max: Self) -> Self251     pub fn clamp(self, min: Self, max: Self) -> Self {
252         glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
253         self.max(min).min(max)
254     }
255 
256     /// Returns the horizontal minimum of `self`.
257     ///
258     /// In other words this computes `min(x, y, ..)`.
259     #[inline]
260     #[must_use]
min_element(self) -> f32261     pub fn min_element(self) -> f32 {
262         let v = self.0;
263         let v = f32x4_pmin(v, i32x4_shuffle::<2, 2, 1, 1>(v, v));
264         let v = f32x4_pmin(v, i32x4_shuffle::<1, 0, 0, 0>(v, v));
265         f32x4_extract_lane::<0>(v)
266     }
267 
268     /// Returns the horizontal maximum of `self`.
269     ///
270     /// In other words this computes `max(x, y, ..)`.
271     #[inline]
272     #[must_use]
max_element(self) -> f32273     pub fn max_element(self) -> f32 {
274         let v = self.0;
275         let v = f32x4_pmax(v, i32x4_shuffle::<2, 2, 0, 0>(v, v));
276         let v = f32x4_pmax(v, i32x4_shuffle::<1, 0, 0, 0>(v, v));
277         f32x4_extract_lane::<0>(v)
278     }
279 
280     /// Returns the sum of all elements of `self`.
281     ///
282     /// In other words, this computes `self.x + self.y + ..`.
283     #[inline]
284     #[must_use]
element_sum(self) -> f32285     pub fn element_sum(self) -> f32 {
286         let v = self.0;
287         let v = f32x4_add(v, i32x4_shuffle::<1, 0, 4, 0>(v, Self::ZERO.0));
288         let v = f32x4_add(v, i32x4_shuffle::<2, 0, 0, 0>(v, v));
289         f32x4_extract_lane::<0>(v)
290     }
291 
292     /// Returns the product of all elements of `self`.
293     ///
294     /// In other words, this computes `self.x * self.y * ..`.
295     #[inline]
296     #[must_use]
element_product(self) -> f32297     pub fn element_product(self) -> f32 {
298         let v = self.0;
299         let v = f32x4_mul(v, i32x4_shuffle::<1, 0, 4, 0>(v, Self::ONE.0));
300         let v = f32x4_mul(v, i32x4_shuffle::<2, 0, 0, 0>(v, v));
301         f32x4_extract_lane::<0>(v)
302     }
303 
304     /// Returns a vector mask containing the result of a `==` comparison for each element of
305     /// `self` and `rhs`.
306     ///
307     /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all
308     /// elements.
309     #[inline]
310     #[must_use]
cmpeq(self, rhs: Self) -> BVec3A311     pub fn cmpeq(self, rhs: Self) -> BVec3A {
312         BVec3A(f32x4_eq(self.0, rhs.0))
313     }
314 
315     /// Returns a vector mask containing the result of a `!=` comparison for each element of
316     /// `self` and `rhs`.
317     ///
318     /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all
319     /// elements.
320     #[inline]
321     #[must_use]
cmpne(self, rhs: Self) -> BVec3A322     pub fn cmpne(self, rhs: Self) -> BVec3A {
323         BVec3A(f32x4_ne(self.0, rhs.0))
324     }
325 
326     /// Returns a vector mask containing the result of a `>=` comparison for each element of
327     /// `self` and `rhs`.
328     ///
329     /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all
330     /// elements.
331     #[inline]
332     #[must_use]
cmpge(self, rhs: Self) -> BVec3A333     pub fn cmpge(self, rhs: Self) -> BVec3A {
334         BVec3A(f32x4_ge(self.0, rhs.0))
335     }
336 
337     /// Returns a vector mask containing the result of a `>` comparison for each element of
338     /// `self` and `rhs`.
339     ///
340     /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all
341     /// elements.
342     #[inline]
343     #[must_use]
cmpgt(self, rhs: Self) -> BVec3A344     pub fn cmpgt(self, rhs: Self) -> BVec3A {
345         BVec3A(f32x4_gt(self.0, rhs.0))
346     }
347 
348     /// Returns a vector mask containing the result of a `<=` comparison for each element of
349     /// `self` and `rhs`.
350     ///
351     /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all
352     /// elements.
353     #[inline]
354     #[must_use]
cmple(self, rhs: Self) -> BVec3A355     pub fn cmple(self, rhs: Self) -> BVec3A {
356         BVec3A(f32x4_le(self.0, rhs.0))
357     }
358 
359     /// Returns a vector mask containing the result of a `<` comparison for each element of
360     /// `self` and `rhs`.
361     ///
362     /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all
363     /// elements.
364     #[inline]
365     #[must_use]
cmplt(self, rhs: Self) -> BVec3A366     pub fn cmplt(self, rhs: Self) -> BVec3A {
367         BVec3A(f32x4_lt(self.0, rhs.0))
368     }
369 
370     /// Returns a vector containing the absolute value of each element of `self`.
371     #[inline]
372     #[must_use]
abs(self) -> Self373     pub fn abs(self) -> Self {
374         Self(f32x4_abs(self.0))
375     }
376 
377     /// Returns a vector with elements representing the sign of `self`.
378     ///
379     /// - `1.0` if the number is positive, `+0.0` or `INFINITY`
380     /// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY`
381     /// - `NAN` if the number is `NAN`
382     #[inline]
383     #[must_use]
signum(self) -> Self384     pub fn signum(self) -> Self {
385         let result = Self(v128_or(v128_and(self.0, Self::NEG_ONE.0), Self::ONE.0));
386         let mask = self.is_nan_mask();
387         Self::select(mask, self, result)
388     }
389 
390     /// Returns a vector with signs of `rhs` and the magnitudes of `self`.
391     #[inline]
392     #[must_use]
copysign(self, rhs: Self) -> Self393     pub fn copysign(self, rhs: Self) -> Self {
394         let mask = Self::splat(-0.0);
395         Self(v128_or(
396             v128_and(rhs.0, mask.0),
397             v128_andnot(self.0, mask.0),
398         ))
399     }
400 
401     /// Returns a bitmask with the lowest 3 bits set to the sign bits from the elements of `self`.
402     ///
403     /// A negative element results in a `1` bit and a positive element in a `0` bit.  Element `x` goes
404     /// into the first lowest bit, element `y` into the second, etc.
405     #[inline]
406     #[must_use]
is_negative_bitmask(self) -> u32407     pub fn is_negative_bitmask(self) -> u32 {
408         (u32x4_bitmask(self.0) & 0x7) as u32
409     }
410 
411     /// Returns `true` if, and only if, all elements are finite.  If any element is either
412     /// `NaN`, positive or negative infinity, this will return `false`.
413     #[inline]
414     #[must_use]
is_finite(self) -> bool415     pub fn is_finite(self) -> bool {
416         self.is_finite_mask().all()
417     }
418 
419     /// Performs `is_finite` on each element of self, returning a vector mask of the results.
420     ///
421     /// In other words, this computes `[x.is_finite(), y.is_finite(), ...]`.
is_finite_mask(self) -> BVec3A422     pub fn is_finite_mask(self) -> BVec3A {
423         BVec3A(f32x4_lt(f32x4_abs(self.0), Self::INFINITY.0))
424     }
425 
426     /// Returns `true` if any elements are `NaN`.
427     #[inline]
428     #[must_use]
is_nan(self) -> bool429     pub fn is_nan(self) -> bool {
430         self.is_nan_mask().any()
431     }
432 
433     /// Performs `is_nan` on each element of self, returning a vector mask of the results.
434     ///
435     /// In other words, this computes `[x.is_nan(), y.is_nan(), ...]`.
436     #[inline]
437     #[must_use]
is_nan_mask(self) -> BVec3A438     pub fn is_nan_mask(self) -> BVec3A {
439         BVec3A(f32x4_ne(self.0, self.0))
440     }
441 
442     /// Computes the length of `self`.
443     #[doc(alias = "magnitude")]
444     #[inline]
445     #[must_use]
length(self) -> f32446     pub fn length(self) -> f32 {
447         let dot = dot3_in_x(self.0, self.0);
448         f32x4_extract_lane::<0>(f32x4_sqrt(dot))
449     }
450 
451     /// Computes the squared length of `self`.
452     ///
453     /// This is faster than `length()` as it avoids a square root operation.
454     #[doc(alias = "magnitude2")]
455     #[inline]
456     #[must_use]
length_squared(self) -> f32457     pub fn length_squared(self) -> f32 {
458         self.dot(self)
459     }
460 
461     /// Computes `1.0 / length()`.
462     ///
463     /// For valid results, `self` must _not_ be of length zero.
464     #[inline]
465     #[must_use]
length_recip(self) -> f32466     pub fn length_recip(self) -> f32 {
467         let dot = dot3_in_x(self.0, self.0);
468         f32x4_extract_lane::<0>(f32x4_div(Self::ONE.0, f32x4_sqrt(dot)))
469     }
470 
471     /// Computes the Euclidean distance between two points in space.
472     #[inline]
473     #[must_use]
distance(self, rhs: Self) -> f32474     pub fn distance(self, rhs: Self) -> f32 {
475         (self - rhs).length()
476     }
477 
478     /// Compute the squared euclidean distance between two points in space.
479     #[inline]
480     #[must_use]
distance_squared(self, rhs: Self) -> f32481     pub fn distance_squared(self, rhs: Self) -> f32 {
482         (self - rhs).length_squared()
483     }
484 
485     /// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`.
486     #[inline]
487     #[must_use]
div_euclid(self, rhs: Self) -> Self488     pub fn div_euclid(self, rhs: Self) -> Self {
489         Self::new(
490             math::div_euclid(self.x, rhs.x),
491             math::div_euclid(self.y, rhs.y),
492             math::div_euclid(self.z, rhs.z),
493         )
494     }
495 
496     /// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`.
497     ///
498     /// [Euclidean division]: f32::rem_euclid
499     #[inline]
500     #[must_use]
rem_euclid(self, rhs: Self) -> Self501     pub fn rem_euclid(self, rhs: Self) -> Self {
502         Self::new(
503             math::rem_euclid(self.x, rhs.x),
504             math::rem_euclid(self.y, rhs.y),
505             math::rem_euclid(self.z, rhs.z),
506         )
507     }
508 
509     /// Returns `self` normalized to length 1.0.
510     ///
511     /// For valid results, `self` must be finite and _not_ of length zero, nor very close to zero.
512     ///
513     /// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`].
514     ///
515     /// Panics
516     ///
517     /// Will panic if the resulting normalized vector is not finite when `glam_assert` is enabled.
518     #[inline]
519     #[must_use]
normalize(self) -> Self520     pub fn normalize(self) -> Self {
521         let length = f32x4_sqrt(dot3_into_v128(self.0, self.0));
522         #[allow(clippy::let_and_return)]
523         let normalized = Self(f32x4_div(self.0, length));
524         glam_assert!(normalized.is_finite());
525         normalized
526     }
527 
528     /// Returns `self` normalized to length 1.0 if possible, else returns `None`.
529     ///
530     /// In particular, if the input is zero (or very close to zero), or non-finite,
531     /// the result of this operation will be `None`.
532     ///
533     /// See also [`Self::normalize_or_zero()`].
534     #[inline]
535     #[must_use]
try_normalize(self) -> Option<Self>536     pub fn try_normalize(self) -> Option<Self> {
537         let rcp = self.length_recip();
538         if rcp.is_finite() && rcp > 0.0 {
539             Some(self * rcp)
540         } else {
541             None
542         }
543     }
544 
545     /// Returns `self` normalized to length 1.0 if possible, else returns a
546     /// fallback value.
547     ///
548     /// In particular, if the input is zero (or very close to zero), or non-finite,
549     /// the result of this operation will be the fallback value.
550     ///
551     /// See also [`Self::try_normalize()`].
552     #[inline]
553     #[must_use]
normalize_or(self, fallback: Self) -> Self554     pub fn normalize_or(self, fallback: Self) -> Self {
555         let rcp = self.length_recip();
556         if rcp.is_finite() && rcp > 0.0 {
557             self * rcp
558         } else {
559             fallback
560         }
561     }
562 
563     /// Returns `self` normalized to length 1.0 if possible, else returns zero.
564     ///
565     /// In particular, if the input is zero (or very close to zero), or non-finite,
566     /// the result of this operation will be zero.
567     ///
568     /// See also [`Self::try_normalize()`].
569     #[inline]
570     #[must_use]
normalize_or_zero(self) -> Self571     pub fn normalize_or_zero(self) -> Self {
572         self.normalize_or(Self::ZERO)
573     }
574 
575     /// Returns whether `self` is length `1.0` or not.
576     ///
577     /// Uses a precision threshold of approximately `1e-4`.
578     #[inline]
579     #[must_use]
is_normalized(self) -> bool580     pub fn is_normalized(self) -> bool {
581         math::abs(self.length_squared() - 1.0) <= 2e-4
582     }
583 
584     /// Returns the vector projection of `self` onto `rhs`.
585     ///
586     /// `rhs` must be of non-zero length.
587     ///
588     /// # Panics
589     ///
590     /// Will panic if `rhs` is zero length when `glam_assert` is enabled.
591     #[inline]
592     #[must_use]
project_onto(self, rhs: Self) -> Self593     pub fn project_onto(self, rhs: Self) -> Self {
594         let other_len_sq_rcp = rhs.dot(rhs).recip();
595         glam_assert!(other_len_sq_rcp.is_finite());
596         rhs * self.dot(rhs) * other_len_sq_rcp
597     }
598 
599     /// Returns the vector rejection of `self` from `rhs`.
600     ///
601     /// The vector rejection is the vector perpendicular to the projection of `self` onto
602     /// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`.
603     ///
604     /// `rhs` must be of non-zero length.
605     ///
606     /// # Panics
607     ///
608     /// Will panic if `rhs` has a length of zero when `glam_assert` is enabled.
609     #[doc(alias("plane"))]
610     #[inline]
611     #[must_use]
reject_from(self, rhs: Self) -> Self612     pub fn reject_from(self, rhs: Self) -> Self {
613         self - self.project_onto(rhs)
614     }
615 
616     /// Returns the vector projection of `self` onto `rhs`.
617     ///
618     /// `rhs` must be normalized.
619     ///
620     /// # Panics
621     ///
622     /// Will panic if `rhs` is not normalized when `glam_assert` is enabled.
623     #[inline]
624     #[must_use]
project_onto_normalized(self, rhs: Self) -> Self625     pub fn project_onto_normalized(self, rhs: Self) -> Self {
626         glam_assert!(rhs.is_normalized());
627         rhs * self.dot(rhs)
628     }
629 
630     /// Returns the vector rejection of `self` from `rhs`.
631     ///
632     /// The vector rejection is the vector perpendicular to the projection of `self` onto
633     /// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`.
634     ///
635     /// `rhs` must be normalized.
636     ///
637     /// # Panics
638     ///
639     /// Will panic if `rhs` is not normalized when `glam_assert` is enabled.
640     #[doc(alias("plane"))]
641     #[inline]
642     #[must_use]
reject_from_normalized(self, rhs: Self) -> Self643     pub fn reject_from_normalized(self, rhs: Self) -> Self {
644         self - self.project_onto_normalized(rhs)
645     }
646 
647     /// Returns a vector containing the nearest integer to a number for each element of `self`.
648     /// Round half-way cases away from 0.0.
649     #[inline]
650     #[must_use]
round(self) -> Self651     pub fn round(self) -> Self {
652         Self(f32x4_nearest(self.0))
653     }
654 
655     /// Returns a vector containing the largest integer less than or equal to a number for each
656     /// element of `self`.
657     #[inline]
658     #[must_use]
floor(self) -> Self659     pub fn floor(self) -> Self {
660         Self(f32x4_floor(self.0))
661     }
662 
663     /// Returns a vector containing the smallest integer greater than or equal to a number for
664     /// each element of `self`.
665     #[inline]
666     #[must_use]
ceil(self) -> Self667     pub fn ceil(self) -> Self {
668         Self(f32x4_ceil(self.0))
669     }
670 
671     /// Returns a vector containing the integer part each element of `self`. This means numbers are
672     /// always truncated towards zero.
673     #[inline]
674     #[must_use]
trunc(self) -> Self675     pub fn trunc(self) -> Self {
676         Self(f32x4_trunc(self.0))
677     }
678 
679     /// Returns a vector containing the fractional part of the vector as `self - self.trunc()`.
680     ///
681     /// Note that this differs from the GLSL implementation of `fract` which returns
682     /// `self - self.floor()`.
683     ///
684     /// Note that this is fast but not precise for large numbers.
685     #[inline]
686     #[must_use]
fract(self) -> Self687     pub fn fract(self) -> Self {
688         self - self.trunc()
689     }
690 
691     /// Returns a vector containing the fractional part of the vector as `self - self.floor()`.
692     ///
693     /// Note that this differs from the Rust implementation of `fract` which returns
694     /// `self - self.trunc()`.
695     ///
696     /// Note that this is fast but not precise for large numbers.
697     #[inline]
698     #[must_use]
fract_gl(self) -> Self699     pub fn fract_gl(self) -> Self {
700         self - self.floor()
701     }
702 
703     /// Returns a vector containing `e^self` (the exponential function) for each element of
704     /// `self`.
705     #[inline]
706     #[must_use]
exp(self) -> Self707     pub fn exp(self) -> Self {
708         Self::new(math::exp(self.x), math::exp(self.y), math::exp(self.z))
709     }
710 
711     /// Returns a vector containing each element of `self` raised to the power of `n`.
712     #[inline]
713     #[must_use]
powf(self, n: f32) -> Self714     pub fn powf(self, n: f32) -> Self {
715         Self::new(
716             math::powf(self.x, n),
717             math::powf(self.y, n),
718             math::powf(self.z, n),
719         )
720     }
721 
722     /// Returns a vector containing the reciprocal `1.0/n` of each element of `self`.
723     #[inline]
724     #[must_use]
recip(self) -> Self725     pub fn recip(self) -> Self {
726         Self(f32x4_div(Self::ONE.0, self.0))
727     }
728 
729     /// Performs a linear interpolation between `self` and `rhs` based on the value `s`.
730     ///
731     /// When `s` is `0.0`, the result will be equal to `self`.  When `s` is `1.0`, the result
732     /// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly
733     /// extrapolated.
734     #[doc(alias = "mix")]
735     #[inline]
736     #[must_use]
lerp(self, rhs: Self, s: f32) -> Self737     pub fn lerp(self, rhs: Self, s: f32) -> Self {
738         self * (1.0 - s) + rhs * s
739     }
740 
741     /// Moves towards `rhs` based on the value `d`.
742     ///
743     /// When `d` is `0.0`, the result will be equal to `self`. When `d` is equal to
744     /// `self.distance(rhs)`, the result will be equal to `rhs`. Will not go past `rhs`.
745     #[inline]
746     #[must_use]
move_towards(&self, rhs: Self, d: f32) -> Self747     pub fn move_towards(&self, rhs: Self, d: f32) -> Self {
748         let a = rhs - *self;
749         let len = a.length();
750         if len <= d || len <= 1e-4 {
751             return rhs;
752         }
753         *self + a / len * d
754     }
755 
756     /// Calculates the midpoint between `self` and `rhs`.
757     ///
758     /// The midpoint is the average of, or halfway point between, two vectors.
759     /// `a.midpoint(b)` should yield the same result as `a.lerp(b, 0.5)`
760     /// while being slightly cheaper to compute.
761     #[inline]
midpoint(self, rhs: Self) -> Self762     pub fn midpoint(self, rhs: Self) -> Self {
763         (self + rhs) * 0.5
764     }
765 
766     /// Returns true if the absolute difference of all elements between `self` and `rhs` is
767     /// less than or equal to `max_abs_diff`.
768     ///
769     /// This can be used to compare if two vectors contain similar elements. It works best when
770     /// comparing with a known value. The `max_abs_diff` that should be used used depends on
771     /// the values being compared against.
772     ///
773     /// For more see
774     /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/).
775     #[inline]
776     #[must_use]
abs_diff_eq(self, rhs: Self, max_abs_diff: f32) -> bool777     pub fn abs_diff_eq(self, rhs: Self, max_abs_diff: f32) -> bool {
778         self.sub(rhs).abs().cmple(Self::splat(max_abs_diff)).all()
779     }
780 
781     /// Returns a vector with a length no less than `min` and no more than `max`.
782     ///
783     /// # Panics
784     ///
785     /// Will panic if `min` is greater than `max`, or if either `min` or `max` is negative, when `glam_assert` is enabled.
786     #[inline]
787     #[must_use]
clamp_length(self, min: f32, max: f32) -> Self788     pub fn clamp_length(self, min: f32, max: f32) -> Self {
789         glam_assert!(0.0 <= min);
790         glam_assert!(min <= max);
791         let length_sq = self.length_squared();
792         if length_sq < min * min {
793             min * (self / math::sqrt(length_sq))
794         } else if length_sq > max * max {
795             max * (self / math::sqrt(length_sq))
796         } else {
797             self
798         }
799     }
800 
801     /// Returns a vector with a length no more than `max`.
802     ///
803     /// # Panics
804     ///
805     /// Will panic if `max` is negative when `glam_assert` is enabled.
806     #[inline]
807     #[must_use]
clamp_length_max(self, max: f32) -> Self808     pub fn clamp_length_max(self, max: f32) -> Self {
809         glam_assert!(0.0 <= max);
810         let length_sq = self.length_squared();
811         if length_sq > max * max {
812             max * (self / math::sqrt(length_sq))
813         } else {
814             self
815         }
816     }
817 
818     /// Returns a vector with a length no less than `min`.
819     ///
820     /// # Panics
821     ///
822     /// Will panic if `min` is negative when `glam_assert` is enabled.
823     #[inline]
824     #[must_use]
clamp_length_min(self, min: f32) -> Self825     pub fn clamp_length_min(self, min: f32) -> Self {
826         glam_assert!(0.0 <= min);
827         let length_sq = self.length_squared();
828         if length_sq < min * min {
829             min * (self / math::sqrt(length_sq))
830         } else {
831             self
832         }
833     }
834 
835     /// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding
836     /// error, yielding a more accurate result than an unfused multiply-add.
837     ///
838     /// Using `mul_add` *may* be more performant than an unfused multiply-add if the target
839     /// architecture has a dedicated fma CPU instruction. However, this is not always true,
840     /// and will be heavily dependant on designing algorithms with specific target hardware in
841     /// mind.
842     #[inline]
843     #[must_use]
mul_add(self, a: Self, b: Self) -> Self844     pub fn mul_add(self, a: Self, b: Self) -> Self {
845         Self::new(
846             math::mul_add(self.x, a.x, b.x),
847             math::mul_add(self.y, a.y, b.y),
848             math::mul_add(self.z, a.z, b.z),
849         )
850     }
851 
852     /// Returns the reflection vector for a given incident vector `self` and surface normal
853     /// `normal`.
854     ///
855     /// `normal` must be normalized.
856     ///
857     /// # Panics
858     ///
859     /// Will panic if `normal` is not normalized when `glam_assert` is enabled.
860     #[inline]
861     #[must_use]
reflect(self, normal: Self) -> Self862     pub fn reflect(self, normal: Self) -> Self {
863         glam_assert!(normal.is_normalized());
864         self - 2.0 * self.dot(normal) * normal
865     }
866 
867     /// Returns the refraction direction for a given incident vector `self`, surface normal
868     /// `normal` and ratio of indices of refraction, `eta`. When total internal reflection occurs,
869     /// a zero vector will be returned.
870     ///
871     /// `self` and `normal` must be normalized.
872     ///
873     /// # Panics
874     ///
875     /// Will panic if `self` or `normal` is not normalized when `glam_assert` is enabled.
876     #[inline]
877     #[must_use]
refract(self, normal: Self, eta: f32) -> Self878     pub fn refract(self, normal: Self, eta: f32) -> Self {
879         glam_assert!(self.is_normalized());
880         glam_assert!(normal.is_normalized());
881         let n_dot_i = normal.dot(self);
882         let k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
883         if k >= 0.0 {
884             eta * self - (eta * n_dot_i + math::sqrt(k)) * normal
885         } else {
886             Self::ZERO
887         }
888     }
889 
890     /// Returns the angle (in radians) between two vectors in the range `[0, +π]`.
891     ///
892     /// The inputs do not need to be unit vectors however they must be non-zero.
893     #[inline]
894     #[must_use]
angle_between(self, rhs: Self) -> f32895     pub fn angle_between(self, rhs: Self) -> f32 {
896         math::acos_approx(
897             self.dot(rhs)
898                 .div(math::sqrt(self.length_squared().mul(rhs.length_squared()))),
899         )
900     }
901 
902     /// Returns some vector that is orthogonal to the given one.
903     ///
904     /// The input vector must be finite and non-zero.
905     ///
906     /// The output vector is not necessarily unit length. For that use
907     /// [`Self::any_orthonormal_vector()`] instead.
908     #[inline]
909     #[must_use]
any_orthogonal_vector(&self) -> Self910     pub fn any_orthogonal_vector(&self) -> Self {
911         // This can probably be optimized
912         if math::abs(self.x) > math::abs(self.y) {
913             Self::new(-self.z, 0.0, self.x) // self.cross(Self::Y)
914         } else {
915             Self::new(0.0, self.z, -self.y) // self.cross(Self::X)
916         }
917     }
918 
919     /// Returns any unit vector that is orthogonal to the given one.
920     ///
921     /// The input vector must be unit length.
922     ///
923     /// # Panics
924     ///
925     /// Will panic if `self` is not normalized when `glam_assert` is enabled.
926     #[inline]
927     #[must_use]
any_orthonormal_vector(&self) -> Self928     pub fn any_orthonormal_vector(&self) -> Self {
929         glam_assert!(self.is_normalized());
930         // From https://graphics.pixar.com/library/OrthonormalB/paper.pdf
931         let sign = math::signum(self.z);
932         let a = -1.0 / (sign + self.z);
933         let b = self.x * self.y * a;
934         Self::new(b, sign + self.y * self.y * a, -self.y)
935     }
936 
937     /// Given a unit vector return two other vectors that together form an orthonormal
938     /// basis. That is, all three vectors are orthogonal to each other and are normalized.
939     ///
940     /// # Panics
941     ///
942     /// Will panic if `self` is not normalized when `glam_assert` is enabled.
943     #[inline]
944     #[must_use]
any_orthonormal_pair(&self) -> (Self, Self)945     pub fn any_orthonormal_pair(&self) -> (Self, Self) {
946         glam_assert!(self.is_normalized());
947         // From https://graphics.pixar.com/library/OrthonormalB/paper.pdf
948         let sign = math::signum(self.z);
949         let a = -1.0 / (sign + self.z);
950         let b = self.x * self.y * a;
951         (
952             Self::new(1.0 + sign * self.x * self.x * a, sign * b, -sign * self.x),
953             Self::new(b, sign + self.y * self.y * a, -self.y),
954         )
955     }
956 
957     /// Performs a spherical linear interpolation between `self` and `rhs` based on the value `s`.
958     ///
959     /// When `s` is `0.0`, the result will be equal to `self`.  When `s` is `1.0`, the result
960     /// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly
961     /// extrapolated.
962     #[inline]
963     #[must_use]
slerp(self, rhs: Self, s: f32) -> Self964     pub fn slerp(self, rhs: Self, s: f32) -> Self {
965         let self_length = self.length();
966         let rhs_length = rhs.length();
967         // Cosine of the angle between the vectors [-1, 1], or NaN if either vector has a zero length
968         let dot = self.dot(rhs) / (self_length * rhs_length);
969         // If dot is close to 1 or -1, or is NaN the calculations for t1 and t2 break down
970         if math::abs(dot) < 1.0 - 3e-7 {
971             // Angle between the vectors [0, +π]
972             let theta = math::acos_approx(dot);
973             // Sine of the angle between vectors [0, 1]
974             let sin_theta = math::sin(theta);
975             let t1 = math::sin(theta * (1. - s));
976             let t2 = math::sin(theta * s);
977 
978             // Interpolate vector lengths
979             let result_length = self_length.lerp(rhs_length, s);
980             // Scale the vectors to the target length and interpolate them
981             return (self * (result_length / self_length) * t1
982                 + rhs * (result_length / rhs_length) * t2)
983                 * sin_theta.recip();
984         }
985         if dot < 0.0 {
986             // Vectors are almost parallel in opposing directions
987 
988             // Create a rotation from self to rhs along some axis
989             let axis = self.any_orthogonal_vector().normalize().into();
990             let rotation = Quat::from_axis_angle(axis, core::f32::consts::PI * s);
991             // Interpolate vector lengths
992             let result_length = self_length.lerp(rhs_length, s);
993             rotation * self * (result_length / self_length)
994         } else {
995             // Vectors are almost parallel in the same direction, or dot was NaN
996             self.lerp(rhs, s)
997         }
998     }
999 
1000     /// Casts all elements of `self` to `f64`.
1001     #[inline]
1002     #[must_use]
as_dvec3(&self) -> crate::DVec31003     pub fn as_dvec3(&self) -> crate::DVec3 {
1004         crate::DVec3::new(self.x as f64, self.y as f64, self.z as f64)
1005     }
1006 
1007     /// Casts all elements of `self` to `i8`.
1008     #[inline]
1009     #[must_use]
as_i8vec3(&self) -> crate::I8Vec31010     pub fn as_i8vec3(&self) -> crate::I8Vec3 {
1011         crate::I8Vec3::new(self.x as i8, self.y as i8, self.z as i8)
1012     }
1013 
1014     /// Casts all elements of `self` to `u8`.
1015     #[inline]
1016     #[must_use]
as_u8vec3(&self) -> crate::U8Vec31017     pub fn as_u8vec3(&self) -> crate::U8Vec3 {
1018         crate::U8Vec3::new(self.x as u8, self.y as u8, self.z as u8)
1019     }
1020 
1021     /// Casts all elements of `self` to `i16`.
1022     #[inline]
1023     #[must_use]
as_i16vec3(&self) -> crate::I16Vec31024     pub fn as_i16vec3(&self) -> crate::I16Vec3 {
1025         crate::I16Vec3::new(self.x as i16, self.y as i16, self.z as i16)
1026     }
1027 
1028     /// Casts all elements of `self` to `u16`.
1029     #[inline]
1030     #[must_use]
as_u16vec3(&self) -> crate::U16Vec31031     pub fn as_u16vec3(&self) -> crate::U16Vec3 {
1032         crate::U16Vec3::new(self.x as u16, self.y as u16, self.z as u16)
1033     }
1034 
1035     /// Casts all elements of `self` to `i32`.
1036     #[inline]
1037     #[must_use]
as_ivec3(&self) -> crate::IVec31038     pub fn as_ivec3(&self) -> crate::IVec3 {
1039         crate::IVec3::new(self.x as i32, self.y as i32, self.z as i32)
1040     }
1041 
1042     /// Casts all elements of `self` to `u32`.
1043     #[inline]
1044     #[must_use]
as_uvec3(&self) -> crate::UVec31045     pub fn as_uvec3(&self) -> crate::UVec3 {
1046         crate::UVec3::new(self.x as u32, self.y as u32, self.z as u32)
1047     }
1048 
1049     /// Casts all elements of `self` to `i64`.
1050     #[inline]
1051     #[must_use]
as_i64vec3(&self) -> crate::I64Vec31052     pub fn as_i64vec3(&self) -> crate::I64Vec3 {
1053         crate::I64Vec3::new(self.x as i64, self.y as i64, self.z as i64)
1054     }
1055 
1056     /// Casts all elements of `self` to `u64`.
1057     #[inline]
1058     #[must_use]
as_u64vec3(&self) -> crate::U64Vec31059     pub fn as_u64vec3(&self) -> crate::U64Vec3 {
1060         crate::U64Vec3::new(self.x as u64, self.y as u64, self.z as u64)
1061     }
1062 }
1063 
1064 impl Default for Vec3A {
1065     #[inline(always)]
default() -> Self1066     fn default() -> Self {
1067         Self::ZERO
1068     }
1069 }
1070 
1071 impl PartialEq for Vec3A {
1072     #[inline]
eq(&self, rhs: &Self) -> bool1073     fn eq(&self, rhs: &Self) -> bool {
1074         self.cmpeq(*rhs).all()
1075     }
1076 }
1077 
1078 impl Div<Vec3A> for Vec3A {
1079     type Output = Self;
1080     #[inline]
div(self, rhs: Self) -> Self1081     fn div(self, rhs: Self) -> Self {
1082         Self(f32x4_div(self.0, rhs.0))
1083     }
1084 }
1085 
1086 impl Div<&Vec3A> for Vec3A {
1087     type Output = Vec3A;
1088     #[inline]
div(self, rhs: &Vec3A) -> Vec3A1089     fn div(self, rhs: &Vec3A) -> Vec3A {
1090         self.div(*rhs)
1091     }
1092 }
1093 
1094 impl Div<&Vec3A> for &Vec3A {
1095     type Output = Vec3A;
1096     #[inline]
div(self, rhs: &Vec3A) -> Vec3A1097     fn div(self, rhs: &Vec3A) -> Vec3A {
1098         (*self).div(*rhs)
1099     }
1100 }
1101 
1102 impl Div<Vec3A> for &Vec3A {
1103     type Output = Vec3A;
1104     #[inline]
div(self, rhs: Vec3A) -> Vec3A1105     fn div(self, rhs: Vec3A) -> Vec3A {
1106         (*self).div(rhs)
1107     }
1108 }
1109 
1110 impl DivAssign<Vec3A> for Vec3A {
1111     #[inline]
div_assign(&mut self, rhs: Self)1112     fn div_assign(&mut self, rhs: Self) {
1113         self.0 = f32x4_div(self.0, rhs.0);
1114     }
1115 }
1116 
1117 impl DivAssign<&Vec3A> for Vec3A {
1118     #[inline]
div_assign(&mut self, rhs: &Vec3A)1119     fn div_assign(&mut self, rhs: &Vec3A) {
1120         self.div_assign(*rhs)
1121     }
1122 }
1123 
1124 impl Div<f32> for Vec3A {
1125     type Output = Self;
1126     #[inline]
div(self, rhs: f32) -> Self1127     fn div(self, rhs: f32) -> Self {
1128         Self(f32x4_div(self.0, f32x4_splat(rhs)))
1129     }
1130 }
1131 
1132 impl Div<&f32> for Vec3A {
1133     type Output = Vec3A;
1134     #[inline]
div(self, rhs: &f32) -> Vec3A1135     fn div(self, rhs: &f32) -> Vec3A {
1136         self.div(*rhs)
1137     }
1138 }
1139 
1140 impl Div<&f32> for &Vec3A {
1141     type Output = Vec3A;
1142     #[inline]
div(self, rhs: &f32) -> Vec3A1143     fn div(self, rhs: &f32) -> Vec3A {
1144         (*self).div(*rhs)
1145     }
1146 }
1147 
1148 impl Div<f32> for &Vec3A {
1149     type Output = Vec3A;
1150     #[inline]
div(self, rhs: f32) -> Vec3A1151     fn div(self, rhs: f32) -> Vec3A {
1152         (*self).div(rhs)
1153     }
1154 }
1155 
1156 impl DivAssign<f32> for Vec3A {
1157     #[inline]
div_assign(&mut self, rhs: f32)1158     fn div_assign(&mut self, rhs: f32) {
1159         self.0 = f32x4_div(self.0, f32x4_splat(rhs));
1160     }
1161 }
1162 
1163 impl DivAssign<&f32> for Vec3A {
1164     #[inline]
div_assign(&mut self, rhs: &f32)1165     fn div_assign(&mut self, rhs: &f32) {
1166         self.div_assign(*rhs)
1167     }
1168 }
1169 
1170 impl Div<Vec3A> for f32 {
1171     type Output = Vec3A;
1172     #[inline]
div(self, rhs: Vec3A) -> Vec3A1173     fn div(self, rhs: Vec3A) -> Vec3A {
1174         Vec3A(f32x4_div(f32x4_splat(self), rhs.0))
1175     }
1176 }
1177 
1178 impl Div<&Vec3A> for f32 {
1179     type Output = Vec3A;
1180     #[inline]
div(self, rhs: &Vec3A) -> Vec3A1181     fn div(self, rhs: &Vec3A) -> Vec3A {
1182         self.div(*rhs)
1183     }
1184 }
1185 
1186 impl Div<&Vec3A> for &f32 {
1187     type Output = Vec3A;
1188     #[inline]
div(self, rhs: &Vec3A) -> Vec3A1189     fn div(self, rhs: &Vec3A) -> Vec3A {
1190         (*self).div(*rhs)
1191     }
1192 }
1193 
1194 impl Div<Vec3A> for &f32 {
1195     type Output = Vec3A;
1196     #[inline]
div(self, rhs: Vec3A) -> Vec3A1197     fn div(self, rhs: Vec3A) -> Vec3A {
1198         (*self).div(rhs)
1199     }
1200 }
1201 
1202 impl Mul<Vec3A> for Vec3A {
1203     type Output = Self;
1204     #[inline]
mul(self, rhs: Self) -> Self1205     fn mul(self, rhs: Self) -> Self {
1206         Self(f32x4_mul(self.0, rhs.0))
1207     }
1208 }
1209 
1210 impl Mul<&Vec3A> for Vec3A {
1211     type Output = Vec3A;
1212     #[inline]
mul(self, rhs: &Vec3A) -> Vec3A1213     fn mul(self, rhs: &Vec3A) -> Vec3A {
1214         self.mul(*rhs)
1215     }
1216 }
1217 
1218 impl Mul<&Vec3A> for &Vec3A {
1219     type Output = Vec3A;
1220     #[inline]
mul(self, rhs: &Vec3A) -> Vec3A1221     fn mul(self, rhs: &Vec3A) -> Vec3A {
1222         (*self).mul(*rhs)
1223     }
1224 }
1225 
1226 impl Mul<Vec3A> for &Vec3A {
1227     type Output = Vec3A;
1228     #[inline]
mul(self, rhs: Vec3A) -> Vec3A1229     fn mul(self, rhs: Vec3A) -> Vec3A {
1230         (*self).mul(rhs)
1231     }
1232 }
1233 
1234 impl MulAssign<Vec3A> for Vec3A {
1235     #[inline]
mul_assign(&mut self, rhs: Self)1236     fn mul_assign(&mut self, rhs: Self) {
1237         self.0 = f32x4_mul(self.0, rhs.0);
1238     }
1239 }
1240 
1241 impl MulAssign<&Vec3A> for Vec3A {
1242     #[inline]
mul_assign(&mut self, rhs: &Vec3A)1243     fn mul_assign(&mut self, rhs: &Vec3A) {
1244         self.mul_assign(*rhs)
1245     }
1246 }
1247 
1248 impl Mul<f32> for Vec3A {
1249     type Output = Self;
1250     #[inline]
mul(self, rhs: f32) -> Self1251     fn mul(self, rhs: f32) -> Self {
1252         Self(f32x4_mul(self.0, f32x4_splat(rhs)))
1253     }
1254 }
1255 
1256 impl Mul<&f32> for Vec3A {
1257     type Output = Vec3A;
1258     #[inline]
mul(self, rhs: &f32) -> Vec3A1259     fn mul(self, rhs: &f32) -> Vec3A {
1260         self.mul(*rhs)
1261     }
1262 }
1263 
1264 impl Mul<&f32> for &Vec3A {
1265     type Output = Vec3A;
1266     #[inline]
mul(self, rhs: &f32) -> Vec3A1267     fn mul(self, rhs: &f32) -> Vec3A {
1268         (*self).mul(*rhs)
1269     }
1270 }
1271 
1272 impl Mul<f32> for &Vec3A {
1273     type Output = Vec3A;
1274     #[inline]
mul(self, rhs: f32) -> Vec3A1275     fn mul(self, rhs: f32) -> Vec3A {
1276         (*self).mul(rhs)
1277     }
1278 }
1279 
1280 impl MulAssign<f32> for Vec3A {
1281     #[inline]
mul_assign(&mut self, rhs: f32)1282     fn mul_assign(&mut self, rhs: f32) {
1283         self.0 = f32x4_mul(self.0, f32x4_splat(rhs))
1284     }
1285 }
1286 
1287 impl MulAssign<&f32> for Vec3A {
1288     #[inline]
mul_assign(&mut self, rhs: &f32)1289     fn mul_assign(&mut self, rhs: &f32) {
1290         self.mul_assign(*rhs)
1291     }
1292 }
1293 
1294 impl Mul<Vec3A> for f32 {
1295     type Output = Vec3A;
1296     #[inline]
mul(self, rhs: Vec3A) -> Vec3A1297     fn mul(self, rhs: Vec3A) -> Vec3A {
1298         Vec3A(f32x4_mul(f32x4_splat(self), rhs.0))
1299     }
1300 }
1301 
1302 impl Mul<&Vec3A> for f32 {
1303     type Output = Vec3A;
1304     #[inline]
mul(self, rhs: &Vec3A) -> Vec3A1305     fn mul(self, rhs: &Vec3A) -> Vec3A {
1306         self.mul(*rhs)
1307     }
1308 }
1309 
1310 impl Mul<&Vec3A> for &f32 {
1311     type Output = Vec3A;
1312     #[inline]
mul(self, rhs: &Vec3A) -> Vec3A1313     fn mul(self, rhs: &Vec3A) -> Vec3A {
1314         (*self).mul(*rhs)
1315     }
1316 }
1317 
1318 impl Mul<Vec3A> for &f32 {
1319     type Output = Vec3A;
1320     #[inline]
mul(self, rhs: Vec3A) -> Vec3A1321     fn mul(self, rhs: Vec3A) -> Vec3A {
1322         (*self).mul(rhs)
1323     }
1324 }
1325 
1326 impl Add<Vec3A> for Vec3A {
1327     type Output = Self;
1328     #[inline]
add(self, rhs: Self) -> Self1329     fn add(self, rhs: Self) -> Self {
1330         Self(f32x4_add(self.0, rhs.0))
1331     }
1332 }
1333 
1334 impl Add<&Vec3A> for Vec3A {
1335     type Output = Vec3A;
1336     #[inline]
add(self, rhs: &Vec3A) -> Vec3A1337     fn add(self, rhs: &Vec3A) -> Vec3A {
1338         self.add(*rhs)
1339     }
1340 }
1341 
1342 impl Add<&Vec3A> for &Vec3A {
1343     type Output = Vec3A;
1344     #[inline]
add(self, rhs: &Vec3A) -> Vec3A1345     fn add(self, rhs: &Vec3A) -> Vec3A {
1346         (*self).add(*rhs)
1347     }
1348 }
1349 
1350 impl Add<Vec3A> for &Vec3A {
1351     type Output = Vec3A;
1352     #[inline]
add(self, rhs: Vec3A) -> Vec3A1353     fn add(self, rhs: Vec3A) -> Vec3A {
1354         (*self).add(rhs)
1355     }
1356 }
1357 
1358 impl AddAssign<Vec3A> for Vec3A {
1359     #[inline]
add_assign(&mut self, rhs: Self)1360     fn add_assign(&mut self, rhs: Self) {
1361         self.0 = f32x4_add(self.0, rhs.0);
1362     }
1363 }
1364 
1365 impl AddAssign<&Vec3A> for Vec3A {
1366     #[inline]
add_assign(&mut self, rhs: &Vec3A)1367     fn add_assign(&mut self, rhs: &Vec3A) {
1368         self.add_assign(*rhs)
1369     }
1370 }
1371 
1372 impl Add<f32> for Vec3A {
1373     type Output = Self;
1374     #[inline]
add(self, rhs: f32) -> Self1375     fn add(self, rhs: f32) -> Self {
1376         Self(f32x4_add(self.0, f32x4_splat(rhs)))
1377     }
1378 }
1379 
1380 impl Add<&f32> for Vec3A {
1381     type Output = Vec3A;
1382     #[inline]
add(self, rhs: &f32) -> Vec3A1383     fn add(self, rhs: &f32) -> Vec3A {
1384         self.add(*rhs)
1385     }
1386 }
1387 
1388 impl Add<&f32> for &Vec3A {
1389     type Output = Vec3A;
1390     #[inline]
add(self, rhs: &f32) -> Vec3A1391     fn add(self, rhs: &f32) -> Vec3A {
1392         (*self).add(*rhs)
1393     }
1394 }
1395 
1396 impl Add<f32> for &Vec3A {
1397     type Output = Vec3A;
1398     #[inline]
add(self, rhs: f32) -> Vec3A1399     fn add(self, rhs: f32) -> Vec3A {
1400         (*self).add(rhs)
1401     }
1402 }
1403 
1404 impl AddAssign<f32> for Vec3A {
1405     #[inline]
add_assign(&mut self, rhs: f32)1406     fn add_assign(&mut self, rhs: f32) {
1407         self.0 = f32x4_add(self.0, f32x4_splat(rhs));
1408     }
1409 }
1410 
1411 impl AddAssign<&f32> for Vec3A {
1412     #[inline]
add_assign(&mut self, rhs: &f32)1413     fn add_assign(&mut self, rhs: &f32) {
1414         self.add_assign(*rhs)
1415     }
1416 }
1417 
1418 impl Add<Vec3A> for f32 {
1419     type Output = Vec3A;
1420     #[inline]
add(self, rhs: Vec3A) -> Vec3A1421     fn add(self, rhs: Vec3A) -> Vec3A {
1422         Vec3A(f32x4_add(f32x4_splat(self), rhs.0))
1423     }
1424 }
1425 
1426 impl Add<&Vec3A> for f32 {
1427     type Output = Vec3A;
1428     #[inline]
add(self, rhs: &Vec3A) -> Vec3A1429     fn add(self, rhs: &Vec3A) -> Vec3A {
1430         self.add(*rhs)
1431     }
1432 }
1433 
1434 impl Add<&Vec3A> for &f32 {
1435     type Output = Vec3A;
1436     #[inline]
add(self, rhs: &Vec3A) -> Vec3A1437     fn add(self, rhs: &Vec3A) -> Vec3A {
1438         (*self).add(*rhs)
1439     }
1440 }
1441 
1442 impl Add<Vec3A> for &f32 {
1443     type Output = Vec3A;
1444     #[inline]
add(self, rhs: Vec3A) -> Vec3A1445     fn add(self, rhs: Vec3A) -> Vec3A {
1446         (*self).add(rhs)
1447     }
1448 }
1449 
1450 impl Sub<Vec3A> for Vec3A {
1451     type Output = Self;
1452     #[inline]
sub(self, rhs: Self) -> Self1453     fn sub(self, rhs: Self) -> Self {
1454         Self(f32x4_sub(self.0, rhs.0))
1455     }
1456 }
1457 
1458 impl Sub<&Vec3A> for Vec3A {
1459     type Output = Vec3A;
1460     #[inline]
sub(self, rhs: &Vec3A) -> Vec3A1461     fn sub(self, rhs: &Vec3A) -> Vec3A {
1462         self.sub(*rhs)
1463     }
1464 }
1465 
1466 impl Sub<&Vec3A> for &Vec3A {
1467     type Output = Vec3A;
1468     #[inline]
sub(self, rhs: &Vec3A) -> Vec3A1469     fn sub(self, rhs: &Vec3A) -> Vec3A {
1470         (*self).sub(*rhs)
1471     }
1472 }
1473 
1474 impl Sub<Vec3A> for &Vec3A {
1475     type Output = Vec3A;
1476     #[inline]
sub(self, rhs: Vec3A) -> Vec3A1477     fn sub(self, rhs: Vec3A) -> Vec3A {
1478         (*self).sub(rhs)
1479     }
1480 }
1481 
1482 impl SubAssign<Vec3A> for Vec3A {
1483     #[inline]
sub_assign(&mut self, rhs: Vec3A)1484     fn sub_assign(&mut self, rhs: Vec3A) {
1485         self.0 = f32x4_sub(self.0, rhs.0);
1486     }
1487 }
1488 
1489 impl SubAssign<&Vec3A> for Vec3A {
1490     #[inline]
sub_assign(&mut self, rhs: &Vec3A)1491     fn sub_assign(&mut self, rhs: &Vec3A) {
1492         self.sub_assign(*rhs)
1493     }
1494 }
1495 
1496 impl Sub<f32> for Vec3A {
1497     type Output = Self;
1498     #[inline]
sub(self, rhs: f32) -> Self1499     fn sub(self, rhs: f32) -> Self {
1500         Self(f32x4_sub(self.0, f32x4_splat(rhs)))
1501     }
1502 }
1503 
1504 impl Sub<&f32> for Vec3A {
1505     type Output = Vec3A;
1506     #[inline]
sub(self, rhs: &f32) -> Vec3A1507     fn sub(self, rhs: &f32) -> Vec3A {
1508         self.sub(*rhs)
1509     }
1510 }
1511 
1512 impl Sub<&f32> for &Vec3A {
1513     type Output = Vec3A;
1514     #[inline]
sub(self, rhs: &f32) -> Vec3A1515     fn sub(self, rhs: &f32) -> Vec3A {
1516         (*self).sub(*rhs)
1517     }
1518 }
1519 
1520 impl Sub<f32> for &Vec3A {
1521     type Output = Vec3A;
1522     #[inline]
sub(self, rhs: f32) -> Vec3A1523     fn sub(self, rhs: f32) -> Vec3A {
1524         (*self).sub(rhs)
1525     }
1526 }
1527 
1528 impl SubAssign<f32> for Vec3A {
1529     #[inline]
sub_assign(&mut self, rhs: f32)1530     fn sub_assign(&mut self, rhs: f32) {
1531         self.0 = f32x4_sub(self.0, f32x4_splat(rhs))
1532     }
1533 }
1534 
1535 impl SubAssign<&f32> for Vec3A {
1536     #[inline]
sub_assign(&mut self, rhs: &f32)1537     fn sub_assign(&mut self, rhs: &f32) {
1538         self.sub_assign(*rhs)
1539     }
1540 }
1541 
1542 impl Sub<Vec3A> for f32 {
1543     type Output = Vec3A;
1544     #[inline]
sub(self, rhs: Vec3A) -> Vec3A1545     fn sub(self, rhs: Vec3A) -> Vec3A {
1546         Vec3A(f32x4_sub(f32x4_splat(self), rhs.0))
1547     }
1548 }
1549 
1550 impl Sub<&Vec3A> for f32 {
1551     type Output = Vec3A;
1552     #[inline]
sub(self, rhs: &Vec3A) -> Vec3A1553     fn sub(self, rhs: &Vec3A) -> Vec3A {
1554         self.sub(*rhs)
1555     }
1556 }
1557 
1558 impl Sub<&Vec3A> for &f32 {
1559     type Output = Vec3A;
1560     #[inline]
sub(self, rhs: &Vec3A) -> Vec3A1561     fn sub(self, rhs: &Vec3A) -> Vec3A {
1562         (*self).sub(*rhs)
1563     }
1564 }
1565 
1566 impl Sub<Vec3A> for &f32 {
1567     type Output = Vec3A;
1568     #[inline]
sub(self, rhs: Vec3A) -> Vec3A1569     fn sub(self, rhs: Vec3A) -> Vec3A {
1570         (*self).sub(rhs)
1571     }
1572 }
1573 
1574 impl Rem<Vec3A> for Vec3A {
1575     type Output = Self;
1576     #[inline]
rem(self, rhs: Self) -> Self1577     fn rem(self, rhs: Self) -> Self {
1578         let n = f32x4_floor(f32x4_div(self.0, rhs.0));
1579         Self(f32x4_sub(self.0, f32x4_mul(n, rhs.0)))
1580     }
1581 }
1582 
1583 impl Rem<&Vec3A> for Vec3A {
1584     type Output = Vec3A;
1585     #[inline]
rem(self, rhs: &Vec3A) -> Vec3A1586     fn rem(self, rhs: &Vec3A) -> Vec3A {
1587         self.rem(*rhs)
1588     }
1589 }
1590 
1591 impl Rem<&Vec3A> for &Vec3A {
1592     type Output = Vec3A;
1593     #[inline]
rem(self, rhs: &Vec3A) -> Vec3A1594     fn rem(self, rhs: &Vec3A) -> Vec3A {
1595         (*self).rem(*rhs)
1596     }
1597 }
1598 
1599 impl Rem<Vec3A> for &Vec3A {
1600     type Output = Vec3A;
1601     #[inline]
rem(self, rhs: Vec3A) -> Vec3A1602     fn rem(self, rhs: Vec3A) -> Vec3A {
1603         (*self).rem(rhs)
1604     }
1605 }
1606 
1607 impl RemAssign<Vec3A> for Vec3A {
1608     #[inline]
rem_assign(&mut self, rhs: Self)1609     fn rem_assign(&mut self, rhs: Self) {
1610         *self = self.rem(rhs);
1611     }
1612 }
1613 
1614 impl RemAssign<&Vec3A> for Vec3A {
1615     #[inline]
rem_assign(&mut self, rhs: &Vec3A)1616     fn rem_assign(&mut self, rhs: &Vec3A) {
1617         self.rem_assign(*rhs)
1618     }
1619 }
1620 
1621 impl Rem<f32> for Vec3A {
1622     type Output = Self;
1623     #[inline]
rem(self, rhs: f32) -> Self1624     fn rem(self, rhs: f32) -> Self {
1625         self.rem(Self::splat(rhs))
1626     }
1627 }
1628 
1629 impl Rem<&f32> for Vec3A {
1630     type Output = Vec3A;
1631     #[inline]
rem(self, rhs: &f32) -> Vec3A1632     fn rem(self, rhs: &f32) -> Vec3A {
1633         self.rem(*rhs)
1634     }
1635 }
1636 
1637 impl Rem<&f32> for &Vec3A {
1638     type Output = Vec3A;
1639     #[inline]
rem(self, rhs: &f32) -> Vec3A1640     fn rem(self, rhs: &f32) -> Vec3A {
1641         (*self).rem(*rhs)
1642     }
1643 }
1644 
1645 impl Rem<f32> for &Vec3A {
1646     type Output = Vec3A;
1647     #[inline]
rem(self, rhs: f32) -> Vec3A1648     fn rem(self, rhs: f32) -> Vec3A {
1649         (*self).rem(rhs)
1650     }
1651 }
1652 
1653 impl RemAssign<f32> for Vec3A {
1654     #[inline]
rem_assign(&mut self, rhs: f32)1655     fn rem_assign(&mut self, rhs: f32) {
1656         *self = self.rem(Self::splat(rhs));
1657     }
1658 }
1659 
1660 impl RemAssign<&f32> for Vec3A {
1661     #[inline]
rem_assign(&mut self, rhs: &f32)1662     fn rem_assign(&mut self, rhs: &f32) {
1663         self.rem_assign(*rhs)
1664     }
1665 }
1666 
1667 impl Rem<Vec3A> for f32 {
1668     type Output = Vec3A;
1669     #[inline]
rem(self, rhs: Vec3A) -> Vec3A1670     fn rem(self, rhs: Vec3A) -> Vec3A {
1671         Vec3A::splat(self).rem(rhs)
1672     }
1673 }
1674 
1675 impl Rem<&Vec3A> for f32 {
1676     type Output = Vec3A;
1677     #[inline]
rem(self, rhs: &Vec3A) -> Vec3A1678     fn rem(self, rhs: &Vec3A) -> Vec3A {
1679         self.rem(*rhs)
1680     }
1681 }
1682 
1683 impl Rem<&Vec3A> for &f32 {
1684     type Output = Vec3A;
1685     #[inline]
rem(self, rhs: &Vec3A) -> Vec3A1686     fn rem(self, rhs: &Vec3A) -> Vec3A {
1687         (*self).rem(*rhs)
1688     }
1689 }
1690 
1691 impl Rem<Vec3A> for &f32 {
1692     type Output = Vec3A;
1693     #[inline]
rem(self, rhs: Vec3A) -> Vec3A1694     fn rem(self, rhs: Vec3A) -> Vec3A {
1695         (*self).rem(rhs)
1696     }
1697 }
1698 
1699 #[cfg(not(target_arch = "spirv"))]
1700 impl AsRef<[f32; 3]> for Vec3A {
1701     #[inline]
as_ref(&self) -> &[f32; 3]1702     fn as_ref(&self) -> &[f32; 3] {
1703         unsafe { &*(self as *const Vec3A as *const [f32; 3]) }
1704     }
1705 }
1706 
1707 #[cfg(not(target_arch = "spirv"))]
1708 impl AsMut<[f32; 3]> for Vec3A {
1709     #[inline]
as_mut(&mut self) -> &mut [f32; 3]1710     fn as_mut(&mut self) -> &mut [f32; 3] {
1711         unsafe { &mut *(self as *mut Vec3A as *mut [f32; 3]) }
1712     }
1713 }
1714 
1715 impl Sum for Vec3A {
1716     #[inline]
sum<I>(iter: I) -> Self where I: Iterator<Item = Self>,1717     fn sum<I>(iter: I) -> Self
1718     where
1719         I: Iterator<Item = Self>,
1720     {
1721         iter.fold(Self::ZERO, Self::add)
1722     }
1723 }
1724 
1725 impl<'a> Sum<&'a Self> for Vec3A {
1726     #[inline]
sum<I>(iter: I) -> Self where I: Iterator<Item = &'a Self>,1727     fn sum<I>(iter: I) -> Self
1728     where
1729         I: Iterator<Item = &'a Self>,
1730     {
1731         iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
1732     }
1733 }
1734 
1735 impl Product for Vec3A {
1736     #[inline]
product<I>(iter: I) -> Self where I: Iterator<Item = Self>,1737     fn product<I>(iter: I) -> Self
1738     where
1739         I: Iterator<Item = Self>,
1740     {
1741         iter.fold(Self::ONE, Self::mul)
1742     }
1743 }
1744 
1745 impl<'a> Product<&'a Self> for Vec3A {
1746     #[inline]
product<I>(iter: I) -> Self where I: Iterator<Item = &'a Self>,1747     fn product<I>(iter: I) -> Self
1748     where
1749         I: Iterator<Item = &'a Self>,
1750     {
1751         iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
1752     }
1753 }
1754 
1755 impl Neg for Vec3A {
1756     type Output = Self;
1757     #[inline]
neg(self) -> Self1758     fn neg(self) -> Self {
1759         Self(f32x4_neg(self.0))
1760     }
1761 }
1762 
1763 impl Neg for &Vec3A {
1764     type Output = Vec3A;
1765     #[inline]
neg(self) -> Vec3A1766     fn neg(self) -> Vec3A {
1767         (*self).neg()
1768     }
1769 }
1770 
1771 impl Index<usize> for Vec3A {
1772     type Output = f32;
1773     #[inline]
index(&self, index: usize) -> &Self::Output1774     fn index(&self, index: usize) -> &Self::Output {
1775         match index {
1776             0 => &self.x,
1777             1 => &self.y,
1778             2 => &self.z,
1779             _ => panic!("index out of bounds"),
1780         }
1781     }
1782 }
1783 
1784 impl IndexMut<usize> for Vec3A {
1785     #[inline]
index_mut(&mut self, index: usize) -> &mut Self::Output1786     fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1787         match index {
1788             0 => &mut self.x,
1789             1 => &mut self.y,
1790             2 => &mut self.z,
1791             _ => panic!("index out of bounds"),
1792         }
1793     }
1794 }
1795 
1796 impl fmt::Display for Vec3A {
fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result1797     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1798         if let Some(p) = f.precision() {
1799             write!(f, "[{:.*}, {:.*}, {:.*}]", p, self.x, p, self.y, p, self.z)
1800         } else {
1801             write!(f, "[{}, {}, {}]", self.x, self.y, self.z)
1802         }
1803     }
1804 }
1805 
1806 impl fmt::Debug for Vec3A {
fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result1807     fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1808         fmt.debug_tuple(stringify!(Vec3A))
1809             .field(&self.x)
1810             .field(&self.y)
1811             .field(&self.z)
1812             .finish()
1813     }
1814 }
1815 
1816 impl From<Vec3A> for v128 {
1817     #[inline(always)]
from(t: Vec3A) -> Self1818     fn from(t: Vec3A) -> Self {
1819         t.0
1820     }
1821 }
1822 
1823 impl From<v128> for Vec3A {
1824     #[inline(always)]
from(t: v128) -> Self1825     fn from(t: v128) -> Self {
1826         Self(t)
1827     }
1828 }
1829 
1830 impl From<[f32; 3]> for Vec3A {
1831     #[inline]
from(a: [f32; 3]) -> Self1832     fn from(a: [f32; 3]) -> Self {
1833         Self::new(a[0], a[1], a[2])
1834     }
1835 }
1836 
1837 impl From<Vec3A> for [f32; 3] {
1838     #[inline]
from(v: Vec3A) -> Self1839     fn from(v: Vec3A) -> Self {
1840         unsafe { *(&v.0 as *const v128 as *const Self) }
1841     }
1842 }
1843 
1844 impl From<(f32, f32, f32)> for Vec3A {
1845     #[inline]
from(t: (f32, f32, f32)) -> Self1846     fn from(t: (f32, f32, f32)) -> Self {
1847         Self::new(t.0, t.1, t.2)
1848     }
1849 }
1850 
1851 impl From<Vec3A> for (f32, f32, f32) {
1852     #[inline]
from(v: Vec3A) -> Self1853     fn from(v: Vec3A) -> Self {
1854         unsafe { *(&v.0 as *const v128 as *const Self) }
1855     }
1856 }
1857 
1858 impl From<Vec3> for Vec3A {
1859     #[inline]
from(v: Vec3) -> Self1860     fn from(v: Vec3) -> Self {
1861         Self::new(v.x, v.y, v.z)
1862     }
1863 }
1864 
1865 impl From<Vec3A> for Vec3 {
1866     #[inline]
from(v: Vec3A) -> Self1867     fn from(v: Vec3A) -> Self {
1868         unsafe { *(&v.0 as *const v128 as *const Self) }
1869     }
1870 }
1871 
1872 impl From<(Vec2, f32)> for Vec3A {
1873     #[inline]
from((v, z): (Vec2, f32)) -> Self1874     fn from((v, z): (Vec2, f32)) -> Self {
1875         Self::new(v.x, v.y, z)
1876     }
1877 }
1878 
1879 impl Deref for Vec3A {
1880     type Target = crate::deref::Vec3<f32>;
1881     #[inline]
deref(&self) -> &Self::Target1882     fn deref(&self) -> &Self::Target {
1883         unsafe { &*(self as *const Self).cast() }
1884     }
1885 }
1886 
1887 impl DerefMut for Vec3A {
1888     #[inline]
deref_mut(&mut self) -> &mut Self::Target1889     fn deref_mut(&mut self) -> &mut Self::Target {
1890         unsafe { &mut *(self as *mut Self).cast() }
1891     }
1892 }
1893 
1894 impl From<BVec3> for Vec3A {
1895     #[inline]
from(v: BVec3) -> Self1896     fn from(v: BVec3) -> Self {
1897         Self::new(f32::from(v.x), f32::from(v.y), f32::from(v.z))
1898     }
1899 }
1900 
1901 impl From<BVec3A> for Vec3A {
1902     #[inline]
from(v: BVec3A) -> Self1903     fn from(v: BVec3A) -> Self {
1904         let bool_array: [bool; 3] = v.into();
1905         Self::new(
1906             f32::from(bool_array[0]),
1907             f32::from(bool_array[1]),
1908             f32::from(bool_array[2]),
1909         )
1910     }
1911 }
1912