1 // Generated from vec.rs.tera template. Edit the template, not the generated file.
2
3 use crate::{f32::math, sse2::*, 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 #[cfg(target_arch = "x86")]
10 use core::arch::x86::*;
11 #[cfg(target_arch = "x86_64")]
12 use core::arch::x86_64::*;
13
14 #[repr(C)]
15 union UnionCast {
16 a: [f32; 4],
17 v: Vec3A,
18 }
19
20 /// Creates a 3-dimensional vector.
21 #[inline(always)]
22 #[must_use]
vec3a(x: f32, y: f32, z: f32) -> Vec3A23 pub const fn vec3a(x: f32, y: f32, z: f32) -> Vec3A {
24 Vec3A::new(x, y, z)
25 }
26
27 /// A 3-dimensional vector.
28 ///
29 /// SIMD vector types are used for storage on supported platforms for better
30 /// performance than the [`Vec3`] type.
31 ///
32 /// It is possible to convert between [`Vec3`] and [`Vec3A`] types using [`From`]
33 /// or [`Into`] trait implementations.
34 ///
35 /// This type is 16 byte aligned.
36 #[derive(Clone, Copy)]
37 #[repr(transparent)]
38 pub struct Vec3A(pub(crate) __m128);
39
40 impl Vec3A {
41 /// All zeroes.
42 pub const ZERO: Self = Self::splat(0.0);
43
44 /// All ones.
45 pub const ONE: Self = Self::splat(1.0);
46
47 /// All negative ones.
48 pub const NEG_ONE: Self = Self::splat(-1.0);
49
50 /// All `f32::MIN`.
51 pub const MIN: Self = Self::splat(f32::MIN);
52
53 /// All `f32::MAX`.
54 pub const MAX: Self = Self::splat(f32::MAX);
55
56 /// All `f32::NAN`.
57 pub const NAN: Self = Self::splat(f32::NAN);
58
59 /// All `f32::INFINITY`.
60 pub const INFINITY: Self = Self::splat(f32::INFINITY);
61
62 /// All `f32::NEG_INFINITY`.
63 pub const NEG_INFINITY: Self = Self::splat(f32::NEG_INFINITY);
64
65 /// A unit vector pointing along the positive X axis.
66 pub const X: Self = Self::new(1.0, 0.0, 0.0);
67
68 /// A unit vector pointing along the positive Y axis.
69 pub const Y: Self = Self::new(0.0, 1.0, 0.0);
70
71 /// A unit vector pointing along the positive Z axis.
72 pub const Z: Self = Self::new(0.0, 0.0, 1.0);
73
74 /// A unit vector pointing along the negative X axis.
75 pub const NEG_X: Self = Self::new(-1.0, 0.0, 0.0);
76
77 /// A unit vector pointing along the negative Y axis.
78 pub const NEG_Y: Self = Self::new(0.0, -1.0, 0.0);
79
80 /// A unit vector pointing along the negative Z axis.
81 pub const NEG_Z: Self = Self::new(0.0, 0.0, -1.0);
82
83 /// The unit axes.
84 pub const AXES: [Self; 3] = [Self::X, Self::Y, Self::Z];
85
86 /// Creates a new vector.
87 #[inline(always)]
88 #[must_use]
new(x: f32, y: f32, z: f32) -> Self89 pub const fn new(x: f32, y: f32, z: f32) -> Self {
90 unsafe { UnionCast { a: [x, y, z, z] }.v }
91 }
92
93 /// Creates a vector with all elements set to `v`.
94 #[inline]
95 #[must_use]
splat(v: f32) -> Self96 pub const fn splat(v: f32) -> Self {
97 unsafe { UnionCast { a: [v; 4] }.v }
98 }
99
100 /// Returns a vector containing each element of `self` modified by a mapping function `f`.
101 #[inline]
102 #[must_use]
map<F>(self, f: F) -> Self where F: Fn(f32) -> f32,103 pub fn map<F>(self, f: F) -> Self
104 where
105 F: Fn(f32) -> f32,
106 {
107 Self::new(f(self.x), f(self.y), f(self.z))
108 }
109
110 /// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use
111 /// for each element of `self`.
112 ///
113 /// A true element in the mask uses the corresponding element from `if_true`, and false
114 /// uses the element from `if_false`.
115 #[inline]
116 #[must_use]
select(mask: BVec3A, if_true: Self, if_false: Self) -> Self117 pub fn select(mask: BVec3A, if_true: Self, if_false: Self) -> Self {
118 Self(unsafe {
119 _mm_or_ps(
120 _mm_andnot_ps(mask.0, if_false.0),
121 _mm_and_ps(if_true.0, mask.0),
122 )
123 })
124 }
125
126 /// Creates a new vector from an array.
127 #[inline]
128 #[must_use]
from_array(a: [f32; 3]) -> Self129 pub const fn from_array(a: [f32; 3]) -> Self {
130 Self::new(a[0], a[1], a[2])
131 }
132
133 /// `[x, y, z]`
134 #[inline]
135 #[must_use]
to_array(&self) -> [f32; 3]136 pub const fn to_array(&self) -> [f32; 3] {
137 unsafe { *(self as *const Vec3A as *const [f32; 3]) }
138 }
139
140 /// Creates a vector from the first 3 values in `slice`.
141 ///
142 /// # Panics
143 ///
144 /// Panics if `slice` is less than 3 elements long.
145 #[inline]
146 #[must_use]
from_slice(slice: &[f32]) -> Self147 pub const fn from_slice(slice: &[f32]) -> Self {
148 assert!(slice.len() >= 3);
149 Self::new(slice[0], slice[1], slice[2])
150 }
151
152 /// Writes the elements of `self` to the first 3 elements in `slice`.
153 ///
154 /// # Panics
155 ///
156 /// Panics if `slice` is less than 3 elements long.
157 #[inline]
write_to_slice(self, slice: &mut [f32])158 pub fn write_to_slice(self, slice: &mut [f32]) {
159 slice[..3].copy_from_slice(&self.to_array());
160 }
161
162 /// Creates a [`Vec3A`] from the `x`, `y` and `z` elements of `self` discarding `w`.
163 ///
164 /// On architectures where SIMD is supported such as SSE2 on `x86_64` this conversion is a noop.
165 #[inline]
166 #[must_use]
from_vec4(v: Vec4) -> Self167 pub fn from_vec4(v: Vec4) -> Self {
168 Self(v.0)
169 }
170
171 /// Creates a 4D vector from `self` and the given `w` value.
172 #[inline]
173 #[must_use]
extend(self, w: f32) -> Vec4174 pub fn extend(self, w: f32) -> Vec4 {
175 Vec4::new(self.x, self.y, self.z, w)
176 }
177
178 /// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`.
179 ///
180 /// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()].
181 #[inline]
182 #[must_use]
truncate(self) -> Vec2183 pub fn truncate(self) -> Vec2 {
184 use crate::swizzles::Vec3Swizzles;
185 self.xy()
186 }
187
188 /// Creates a 3D vector from `self` with the given value of `x`.
189 #[inline]
190 #[must_use]
with_x(mut self, x: f32) -> Self191 pub fn with_x(mut self, x: f32) -> Self {
192 self.x = x;
193 self
194 }
195
196 /// Creates a 3D vector from `self` with the given value of `y`.
197 #[inline]
198 #[must_use]
with_y(mut self, y: f32) -> Self199 pub fn with_y(mut self, y: f32) -> Self {
200 self.y = y;
201 self
202 }
203
204 /// Creates a 3D vector from `self` with the given value of `z`.
205 #[inline]
206 #[must_use]
with_z(mut self, z: f32) -> Self207 pub fn with_z(mut self, z: f32) -> Self {
208 self.z = z;
209 self
210 }
211
212 /// Computes the dot product of `self` and `rhs`.
213 #[inline]
214 #[must_use]
dot(self, rhs: Self) -> f32215 pub fn dot(self, rhs: Self) -> f32 {
216 unsafe { dot3(self.0, rhs.0) }
217 }
218
219 /// Returns a vector where every component is the dot product of `self` and `rhs`.
220 #[inline]
221 #[must_use]
dot_into_vec(self, rhs: Self) -> Self222 pub fn dot_into_vec(self, rhs: Self) -> Self {
223 Self(unsafe { dot3_into_m128(self.0, rhs.0) })
224 }
225
226 /// Computes the cross product of `self` and `rhs`.
227 #[inline]
228 #[must_use]
cross(self, rhs: Self) -> Self229 pub fn cross(self, rhs: Self) -> Self {
230 unsafe {
231 // x <- a.y*b.z - a.z*b.y
232 // y <- a.z*b.x - a.x*b.z
233 // z <- a.x*b.y - a.y*b.x
234 // We can save a shuffle by grouping it in this wacky order:
235 // (self.zxy() * rhs - self * rhs.zxy()).zxy()
236 let lhszxy = _mm_shuffle_ps(self.0, self.0, 0b01_01_00_10);
237 let rhszxy = _mm_shuffle_ps(rhs.0, rhs.0, 0b01_01_00_10);
238 let lhszxy_rhs = _mm_mul_ps(lhszxy, rhs.0);
239 let rhszxy_lhs = _mm_mul_ps(rhszxy, self.0);
240 let sub = _mm_sub_ps(lhszxy_rhs, rhszxy_lhs);
241 Self(_mm_shuffle_ps(sub, sub, 0b01_01_00_10))
242 }
243 }
244
245 /// Returns a vector containing the minimum values for each element of `self` and `rhs`.
246 ///
247 /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`.
248 #[inline]
249 #[must_use]
min(self, rhs: Self) -> Self250 pub fn min(self, rhs: Self) -> Self {
251 Self(unsafe { _mm_min_ps(self.0, rhs.0) })
252 }
253
254 /// Returns a vector containing the maximum values for each element of `self` and `rhs`.
255 ///
256 /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`.
257 #[inline]
258 #[must_use]
max(self, rhs: Self) -> Self259 pub fn max(self, rhs: Self) -> Self {
260 Self(unsafe { _mm_max_ps(self.0, rhs.0) })
261 }
262
263 /// Component-wise clamping of values, similar to [`f32::clamp`].
264 ///
265 /// Each element in `min` must be less-or-equal to the corresponding element in `max`.
266 ///
267 /// # Panics
268 ///
269 /// Will panic if `min` is greater than `max` when `glam_assert` is enabled.
270 #[inline]
271 #[must_use]
clamp(self, min: Self, max: Self) -> Self272 pub fn clamp(self, min: Self, max: Self) -> Self {
273 glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
274 self.max(min).min(max)
275 }
276
277 /// Returns the horizontal minimum of `self`.
278 ///
279 /// In other words this computes `min(x, y, ..)`.
280 #[inline]
281 #[must_use]
min_element(self) -> f32282 pub fn min_element(self) -> f32 {
283 unsafe {
284 let v = self.0;
285 let v = _mm_min_ps(v, _mm_shuffle_ps(v, v, 0b01_01_10_10));
286 let v = _mm_min_ps(v, _mm_shuffle_ps(v, v, 0b00_00_00_01));
287 _mm_cvtss_f32(v)
288 }
289 }
290
291 /// Returns the horizontal maximum of `self`.
292 ///
293 /// In other words this computes `max(x, y, ..)`.
294 #[inline]
295 #[must_use]
max_element(self) -> f32296 pub fn max_element(self) -> f32 {
297 unsafe {
298 let v = self.0;
299 let v = _mm_max_ps(v, _mm_shuffle_ps(v, v, 0b00_00_10_10));
300 let v = _mm_max_ps(v, _mm_shuffle_ps(v, v, 0b00_00_00_01));
301 _mm_cvtss_f32(v)
302 }
303 }
304
305 /// Returns the sum of all elements of `self`.
306 ///
307 /// In other words, this computes `self.x + self.y + ..`.
308 #[inline]
309 #[must_use]
element_sum(self) -> f32310 pub fn element_sum(self) -> f32 {
311 unsafe {
312 let v = self.0;
313 let v = _mm_add_ps(v, _mm_shuffle_ps(v, Self::ZERO.0, 0b00_11_00_01));
314 let v = _mm_add_ps(v, _mm_shuffle_ps(v, v, 0b00_00_00_10));
315 _mm_cvtss_f32(v)
316 }
317 }
318
319 /// Returns the product of all elements of `self`.
320 ///
321 /// In other words, this computes `self.x * self.y * ..`.
322 #[inline]
323 #[must_use]
element_product(self) -> f32324 pub fn element_product(self) -> f32 {
325 unsafe {
326 let v = self.0;
327 let v = _mm_mul_ps(v, _mm_shuffle_ps(v, Self::ONE.0, 0b00_11_00_01));
328 let v = _mm_mul_ps(v, _mm_shuffle_ps(v, v, 0b00_00_00_10));
329 _mm_cvtss_f32(v)
330 }
331 }
332
333 /// Returns a vector mask containing the result of a `==` comparison for each element of
334 /// `self` and `rhs`.
335 ///
336 /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all
337 /// elements.
338 #[inline]
339 #[must_use]
cmpeq(self, rhs: Self) -> BVec3A340 pub fn cmpeq(self, rhs: Self) -> BVec3A {
341 BVec3A(unsafe { _mm_cmpeq_ps(self.0, rhs.0) })
342 }
343
344 /// Returns a vector mask containing the result of a `!=` comparison for each element of
345 /// `self` and `rhs`.
346 ///
347 /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all
348 /// elements.
349 #[inline]
350 #[must_use]
cmpne(self, rhs: Self) -> BVec3A351 pub fn cmpne(self, rhs: Self) -> BVec3A {
352 BVec3A(unsafe { _mm_cmpneq_ps(self.0, rhs.0) })
353 }
354
355 /// Returns a vector mask containing the result of a `>=` comparison for each element of
356 /// `self` and `rhs`.
357 ///
358 /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all
359 /// elements.
360 #[inline]
361 #[must_use]
cmpge(self, rhs: Self) -> BVec3A362 pub fn cmpge(self, rhs: Self) -> BVec3A {
363 BVec3A(unsafe { _mm_cmpge_ps(self.0, rhs.0) })
364 }
365
366 /// Returns a vector mask containing the result of a `>` comparison for each element of
367 /// `self` and `rhs`.
368 ///
369 /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all
370 /// elements.
371 #[inline]
372 #[must_use]
cmpgt(self, rhs: Self) -> BVec3A373 pub fn cmpgt(self, rhs: Self) -> BVec3A {
374 BVec3A(unsafe { _mm_cmpgt_ps(self.0, rhs.0) })
375 }
376
377 /// Returns a vector mask containing the result of a `<=` comparison for each element of
378 /// `self` and `rhs`.
379 ///
380 /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all
381 /// elements.
382 #[inline]
383 #[must_use]
cmple(self, rhs: Self) -> BVec3A384 pub fn cmple(self, rhs: Self) -> BVec3A {
385 BVec3A(unsafe { _mm_cmple_ps(self.0, rhs.0) })
386 }
387
388 /// Returns a vector mask containing the result of a `<` comparison for each element of
389 /// `self` and `rhs`.
390 ///
391 /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all
392 /// elements.
393 #[inline]
394 #[must_use]
cmplt(self, rhs: Self) -> BVec3A395 pub fn cmplt(self, rhs: Self) -> BVec3A {
396 BVec3A(unsafe { _mm_cmplt_ps(self.0, rhs.0) })
397 }
398
399 /// Returns a vector containing the absolute value of each element of `self`.
400 #[inline]
401 #[must_use]
abs(self) -> Self402 pub fn abs(self) -> Self {
403 Self(unsafe { crate::sse2::m128_abs(self.0) })
404 }
405
406 /// Returns a vector with elements representing the sign of `self`.
407 ///
408 /// - `1.0` if the number is positive, `+0.0` or `INFINITY`
409 /// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY`
410 /// - `NAN` if the number is `NAN`
411 #[inline]
412 #[must_use]
signum(self) -> Self413 pub fn signum(self) -> Self {
414 let result = Self(unsafe { _mm_or_ps(_mm_and_ps(self.0, Self::NEG_ONE.0), Self::ONE.0) });
415 let mask = self.is_nan_mask();
416 Self::select(mask, self, result)
417 }
418
419 /// Returns a vector with signs of `rhs` and the magnitudes of `self`.
420 #[inline]
421 #[must_use]
copysign(self, rhs: Self) -> Self422 pub fn copysign(self, rhs: Self) -> Self {
423 let mask = Self::splat(-0.0);
424 Self(unsafe { _mm_or_ps(_mm_and_ps(rhs.0, mask.0), _mm_andnot_ps(mask.0, self.0)) })
425 }
426
427 /// Returns a bitmask with the lowest 3 bits set to the sign bits from the elements of `self`.
428 ///
429 /// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes
430 /// into the first lowest bit, element `y` into the second, etc.
431 #[inline]
432 #[must_use]
is_negative_bitmask(self) -> u32433 pub fn is_negative_bitmask(self) -> u32 {
434 unsafe { (_mm_movemask_ps(self.0) as u32) & 0x7 }
435 }
436
437 /// Returns `true` if, and only if, all elements are finite. If any element is either
438 /// `NaN`, positive or negative infinity, this will return `false`.
439 #[inline]
440 #[must_use]
is_finite(self) -> bool441 pub fn is_finite(self) -> bool {
442 self.is_finite_mask().all()
443 }
444
445 /// Performs `is_finite` on each element of self, returning a vector mask of the results.
446 ///
447 /// In other words, this computes `[x.is_finite(), y.is_finite(), ...]`.
is_finite_mask(self) -> BVec3A448 pub fn is_finite_mask(self) -> BVec3A {
449 BVec3A(unsafe { _mm_cmplt_ps(crate::sse2::m128_abs(self.0), Self::INFINITY.0) })
450 }
451
452 /// Returns `true` if any elements are `NaN`.
453 #[inline]
454 #[must_use]
is_nan(self) -> bool455 pub fn is_nan(self) -> bool {
456 self.is_nan_mask().any()
457 }
458
459 /// Performs `is_nan` on each element of self, returning a vector mask of the results.
460 ///
461 /// In other words, this computes `[x.is_nan(), y.is_nan(), ...]`.
462 #[inline]
463 #[must_use]
is_nan_mask(self) -> BVec3A464 pub fn is_nan_mask(self) -> BVec3A {
465 BVec3A(unsafe { _mm_cmpunord_ps(self.0, self.0) })
466 }
467
468 /// Computes the length of `self`.
469 #[doc(alias = "magnitude")]
470 #[inline]
471 #[must_use]
length(self) -> f32472 pub fn length(self) -> f32 {
473 unsafe {
474 let dot = dot3_in_x(self.0, self.0);
475 _mm_cvtss_f32(_mm_sqrt_ps(dot))
476 }
477 }
478
479 /// Computes the squared length of `self`.
480 ///
481 /// This is faster than `length()` as it avoids a square root operation.
482 #[doc(alias = "magnitude2")]
483 #[inline]
484 #[must_use]
length_squared(self) -> f32485 pub fn length_squared(self) -> f32 {
486 self.dot(self)
487 }
488
489 /// Computes `1.0 / length()`.
490 ///
491 /// For valid results, `self` must _not_ be of length zero.
492 #[inline]
493 #[must_use]
length_recip(self) -> f32494 pub fn length_recip(self) -> f32 {
495 unsafe {
496 let dot = dot3_in_x(self.0, self.0);
497 _mm_cvtss_f32(_mm_div_ps(Self::ONE.0, _mm_sqrt_ps(dot)))
498 }
499 }
500
501 /// Computes the Euclidean distance between two points in space.
502 #[inline]
503 #[must_use]
distance(self, rhs: Self) -> f32504 pub fn distance(self, rhs: Self) -> f32 {
505 (self - rhs).length()
506 }
507
508 /// Compute the squared euclidean distance between two points in space.
509 #[inline]
510 #[must_use]
distance_squared(self, rhs: Self) -> f32511 pub fn distance_squared(self, rhs: Self) -> f32 {
512 (self - rhs).length_squared()
513 }
514
515 /// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`.
516 #[inline]
517 #[must_use]
div_euclid(self, rhs: Self) -> Self518 pub fn div_euclid(self, rhs: Self) -> Self {
519 Self::new(
520 math::div_euclid(self.x, rhs.x),
521 math::div_euclid(self.y, rhs.y),
522 math::div_euclid(self.z, rhs.z),
523 )
524 }
525
526 /// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`.
527 ///
528 /// [Euclidean division]: f32::rem_euclid
529 #[inline]
530 #[must_use]
rem_euclid(self, rhs: Self) -> Self531 pub fn rem_euclid(self, rhs: Self) -> Self {
532 Self::new(
533 math::rem_euclid(self.x, rhs.x),
534 math::rem_euclid(self.y, rhs.y),
535 math::rem_euclid(self.z, rhs.z),
536 )
537 }
538
539 /// Returns `self` normalized to length 1.0.
540 ///
541 /// For valid results, `self` must be finite and _not_ of length zero, nor very close to zero.
542 ///
543 /// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`].
544 ///
545 /// Panics
546 ///
547 /// Will panic if the resulting normalized vector is not finite when `glam_assert` is enabled.
548 #[inline]
549 #[must_use]
normalize(self) -> Self550 pub fn normalize(self) -> Self {
551 unsafe {
552 let length = _mm_sqrt_ps(dot3_into_m128(self.0, self.0));
553 #[allow(clippy::let_and_return)]
554 let normalized = Self(_mm_div_ps(self.0, length));
555 glam_assert!(normalized.is_finite());
556 normalized
557 }
558 }
559
560 /// Returns `self` normalized to length 1.0 if possible, else returns `None`.
561 ///
562 /// In particular, if the input is zero (or very close to zero), or non-finite,
563 /// the result of this operation will be `None`.
564 ///
565 /// See also [`Self::normalize_or_zero()`].
566 #[inline]
567 #[must_use]
try_normalize(self) -> Option<Self>568 pub fn try_normalize(self) -> Option<Self> {
569 let rcp = self.length_recip();
570 if rcp.is_finite() && rcp > 0.0 {
571 Some(self * rcp)
572 } else {
573 None
574 }
575 }
576
577 /// Returns `self` normalized to length 1.0 if possible, else returns a
578 /// fallback value.
579 ///
580 /// In particular, if the input is zero (or very close to zero), or non-finite,
581 /// the result of this operation will be the fallback value.
582 ///
583 /// See also [`Self::try_normalize()`].
584 #[inline]
585 #[must_use]
normalize_or(self, fallback: Self) -> Self586 pub fn normalize_or(self, fallback: Self) -> Self {
587 let rcp = self.length_recip();
588 if rcp.is_finite() && rcp > 0.0 {
589 self * rcp
590 } else {
591 fallback
592 }
593 }
594
595 /// Returns `self` normalized to length 1.0 if possible, else returns zero.
596 ///
597 /// In particular, if the input is zero (or very close to zero), or non-finite,
598 /// the result of this operation will be zero.
599 ///
600 /// See also [`Self::try_normalize()`].
601 #[inline]
602 #[must_use]
normalize_or_zero(self) -> Self603 pub fn normalize_or_zero(self) -> Self {
604 self.normalize_or(Self::ZERO)
605 }
606
607 /// Returns whether `self` is length `1.0` or not.
608 ///
609 /// Uses a precision threshold of approximately `1e-4`.
610 #[inline]
611 #[must_use]
is_normalized(self) -> bool612 pub fn is_normalized(self) -> bool {
613 math::abs(self.length_squared() - 1.0) <= 2e-4
614 }
615
616 /// Returns the vector projection of `self` onto `rhs`.
617 ///
618 /// `rhs` must be of non-zero length.
619 ///
620 /// # Panics
621 ///
622 /// Will panic if `rhs` is zero length when `glam_assert` is enabled.
623 #[inline]
624 #[must_use]
project_onto(self, rhs: Self) -> Self625 pub fn project_onto(self, rhs: Self) -> Self {
626 let other_len_sq_rcp = rhs.dot(rhs).recip();
627 glam_assert!(other_len_sq_rcp.is_finite());
628 rhs * self.dot(rhs) * other_len_sq_rcp
629 }
630
631 /// Returns the vector rejection of `self` from `rhs`.
632 ///
633 /// The vector rejection is the vector perpendicular to the projection of `self` onto
634 /// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`.
635 ///
636 /// `rhs` must be of non-zero length.
637 ///
638 /// # Panics
639 ///
640 /// Will panic if `rhs` has a length of zero when `glam_assert` is enabled.
641 #[doc(alias("plane"))]
642 #[inline]
643 #[must_use]
reject_from(self, rhs: Self) -> Self644 pub fn reject_from(self, rhs: Self) -> Self {
645 self - self.project_onto(rhs)
646 }
647
648 /// Returns the vector projection of `self` onto `rhs`.
649 ///
650 /// `rhs` must be normalized.
651 ///
652 /// # Panics
653 ///
654 /// Will panic if `rhs` is not normalized when `glam_assert` is enabled.
655 #[inline]
656 #[must_use]
project_onto_normalized(self, rhs: Self) -> Self657 pub fn project_onto_normalized(self, rhs: Self) -> Self {
658 glam_assert!(rhs.is_normalized());
659 rhs * self.dot(rhs)
660 }
661
662 /// Returns the vector rejection of `self` from `rhs`.
663 ///
664 /// The vector rejection is the vector perpendicular to the projection of `self` onto
665 /// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`.
666 ///
667 /// `rhs` must be normalized.
668 ///
669 /// # Panics
670 ///
671 /// Will panic if `rhs` is not normalized when `glam_assert` is enabled.
672 #[doc(alias("plane"))]
673 #[inline]
674 #[must_use]
reject_from_normalized(self, rhs: Self) -> Self675 pub fn reject_from_normalized(self, rhs: Self) -> Self {
676 self - self.project_onto_normalized(rhs)
677 }
678
679 /// Returns a vector containing the nearest integer to a number for each element of `self`.
680 /// Round half-way cases away from 0.0.
681 #[inline]
682 #[must_use]
round(self) -> Self683 pub fn round(self) -> Self {
684 Self(unsafe { m128_round(self.0) })
685 }
686
687 /// Returns a vector containing the largest integer less than or equal to a number for each
688 /// element of `self`.
689 #[inline]
690 #[must_use]
floor(self) -> Self691 pub fn floor(self) -> Self {
692 Self(unsafe { m128_floor(self.0) })
693 }
694
695 /// Returns a vector containing the smallest integer greater than or equal to a number for
696 /// each element of `self`.
697 #[inline]
698 #[must_use]
ceil(self) -> Self699 pub fn ceil(self) -> Self {
700 Self(unsafe { m128_ceil(self.0) })
701 }
702
703 /// Returns a vector containing the integer part each element of `self`. This means numbers are
704 /// always truncated towards zero.
705 #[inline]
706 #[must_use]
trunc(self) -> Self707 pub fn trunc(self) -> Self {
708 Self(unsafe { m128_trunc(self.0) })
709 }
710
711 /// Returns a vector containing the fractional part of the vector as `self - self.trunc()`.
712 ///
713 /// Note that this differs from the GLSL implementation of `fract` which returns
714 /// `self - self.floor()`.
715 ///
716 /// Note that this is fast but not precise for large numbers.
717 #[inline]
718 #[must_use]
fract(self) -> Self719 pub fn fract(self) -> Self {
720 self - self.trunc()
721 }
722
723 /// Returns a vector containing the fractional part of the vector as `self - self.floor()`.
724 ///
725 /// Note that this differs from the Rust implementation of `fract` which returns
726 /// `self - self.trunc()`.
727 ///
728 /// Note that this is fast but not precise for large numbers.
729 #[inline]
730 #[must_use]
fract_gl(self) -> Self731 pub fn fract_gl(self) -> Self {
732 self - self.floor()
733 }
734
735 /// Returns a vector containing `e^self` (the exponential function) for each element of
736 /// `self`.
737 #[inline]
738 #[must_use]
exp(self) -> Self739 pub fn exp(self) -> Self {
740 Self::new(math::exp(self.x), math::exp(self.y), math::exp(self.z))
741 }
742
743 /// Returns a vector containing each element of `self` raised to the power of `n`.
744 #[inline]
745 #[must_use]
powf(self, n: f32) -> Self746 pub fn powf(self, n: f32) -> Self {
747 Self::new(
748 math::powf(self.x, n),
749 math::powf(self.y, n),
750 math::powf(self.z, n),
751 )
752 }
753
754 /// Returns a vector containing the reciprocal `1.0/n` of each element of `self`.
755 #[inline]
756 #[must_use]
recip(self) -> Self757 pub fn recip(self) -> Self {
758 Self(unsafe { _mm_div_ps(Self::ONE.0, self.0) })
759 }
760
761 /// Performs a linear interpolation between `self` and `rhs` based on the value `s`.
762 ///
763 /// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result
764 /// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly
765 /// extrapolated.
766 #[doc(alias = "mix")]
767 #[inline]
768 #[must_use]
lerp(self, rhs: Self, s: f32) -> Self769 pub fn lerp(self, rhs: Self, s: f32) -> Self {
770 self * (1.0 - s) + rhs * s
771 }
772
773 /// Moves towards `rhs` based on the value `d`.
774 ///
775 /// When `d` is `0.0`, the result will be equal to `self`. When `d` is equal to
776 /// `self.distance(rhs)`, the result will be equal to `rhs`. Will not go past `rhs`.
777 #[inline]
778 #[must_use]
move_towards(&self, rhs: Self, d: f32) -> Self779 pub fn move_towards(&self, rhs: Self, d: f32) -> Self {
780 let a = rhs - *self;
781 let len = a.length();
782 if len <= d || len <= 1e-4 {
783 return rhs;
784 }
785 *self + a / len * d
786 }
787
788 /// Calculates the midpoint between `self` and `rhs`.
789 ///
790 /// The midpoint is the average of, or halfway point between, two vectors.
791 /// `a.midpoint(b)` should yield the same result as `a.lerp(b, 0.5)`
792 /// while being slightly cheaper to compute.
793 #[inline]
midpoint(self, rhs: Self) -> Self794 pub fn midpoint(self, rhs: Self) -> Self {
795 (self + rhs) * 0.5
796 }
797
798 /// Returns true if the absolute difference of all elements between `self` and `rhs` is
799 /// less than or equal to `max_abs_diff`.
800 ///
801 /// This can be used to compare if two vectors contain similar elements. It works best when
802 /// comparing with a known value. The `max_abs_diff` that should be used used depends on
803 /// the values being compared against.
804 ///
805 /// For more see
806 /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/).
807 #[inline]
808 #[must_use]
abs_diff_eq(self, rhs: Self, max_abs_diff: f32) -> bool809 pub fn abs_diff_eq(self, rhs: Self, max_abs_diff: f32) -> bool {
810 self.sub(rhs).abs().cmple(Self::splat(max_abs_diff)).all()
811 }
812
813 /// Returns a vector with a length no less than `min` and no more than `max`.
814 ///
815 /// # Panics
816 ///
817 /// Will panic if `min` is greater than `max`, or if either `min` or `max` is negative, when `glam_assert` is enabled.
818 #[inline]
819 #[must_use]
clamp_length(self, min: f32, max: f32) -> Self820 pub fn clamp_length(self, min: f32, max: f32) -> Self {
821 glam_assert!(0.0 <= min);
822 glam_assert!(min <= max);
823 let length_sq = self.length_squared();
824 if length_sq < min * min {
825 min * (self / math::sqrt(length_sq))
826 } else if length_sq > max * max {
827 max * (self / math::sqrt(length_sq))
828 } else {
829 self
830 }
831 }
832
833 /// Returns a vector with a length no more than `max`.
834 ///
835 /// # Panics
836 ///
837 /// Will panic if `max` is negative when `glam_assert` is enabled.
838 #[inline]
839 #[must_use]
clamp_length_max(self, max: f32) -> Self840 pub fn clamp_length_max(self, max: f32) -> Self {
841 glam_assert!(0.0 <= max);
842 let length_sq = self.length_squared();
843 if length_sq > max * max {
844 max * (self / math::sqrt(length_sq))
845 } else {
846 self
847 }
848 }
849
850 /// Returns a vector with a length no less than `min`.
851 ///
852 /// # Panics
853 ///
854 /// Will panic if `min` is negative when `glam_assert` is enabled.
855 #[inline]
856 #[must_use]
clamp_length_min(self, min: f32) -> Self857 pub fn clamp_length_min(self, min: f32) -> Self {
858 glam_assert!(0.0 <= min);
859 let length_sq = self.length_squared();
860 if length_sq < min * min {
861 min * (self / math::sqrt(length_sq))
862 } else {
863 self
864 }
865 }
866
867 /// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding
868 /// error, yielding a more accurate result than an unfused multiply-add.
869 ///
870 /// Using `mul_add` *may* be more performant than an unfused multiply-add if the target
871 /// architecture has a dedicated fma CPU instruction. However, this is not always true,
872 /// and will be heavily dependant on designing algorithms with specific target hardware in
873 /// mind.
874 #[inline]
875 #[must_use]
mul_add(self, a: Self, b: Self) -> Self876 pub fn mul_add(self, a: Self, b: Self) -> Self {
877 #[cfg(target_feature = "fma")]
878 unsafe {
879 Self(_mm_fmadd_ps(self.0, a.0, b.0))
880 }
881 #[cfg(not(target_feature = "fma"))]
882 Self::new(
883 math::mul_add(self.x, a.x, b.x),
884 math::mul_add(self.y, a.y, b.y),
885 math::mul_add(self.z, a.z, b.z),
886 )
887 }
888
889 /// Returns the reflection vector for a given incident vector `self` and surface normal
890 /// `normal`.
891 ///
892 /// `normal` must be normalized.
893 ///
894 /// # Panics
895 ///
896 /// Will panic if `normal` is not normalized when `glam_assert` is enabled.
897 #[inline]
898 #[must_use]
reflect(self, normal: Self) -> Self899 pub fn reflect(self, normal: Self) -> Self {
900 glam_assert!(normal.is_normalized());
901 self - 2.0 * self.dot(normal) * normal
902 }
903
904 /// Returns the refraction direction for a given incident vector `self`, surface normal
905 /// `normal` and ratio of indices of refraction, `eta`. When total internal reflection occurs,
906 /// a zero vector will be returned.
907 ///
908 /// `self` and `normal` must be normalized.
909 ///
910 /// # Panics
911 ///
912 /// Will panic if `self` or `normal` is not normalized when `glam_assert` is enabled.
913 #[inline]
914 #[must_use]
refract(self, normal: Self, eta: f32) -> Self915 pub fn refract(self, normal: Self, eta: f32) -> Self {
916 glam_assert!(self.is_normalized());
917 glam_assert!(normal.is_normalized());
918 let n_dot_i = normal.dot(self);
919 let k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
920 if k >= 0.0 {
921 eta * self - (eta * n_dot_i + math::sqrt(k)) * normal
922 } else {
923 Self::ZERO
924 }
925 }
926
927 /// Returns the angle (in radians) between two vectors in the range `[0, +π]`.
928 ///
929 /// The inputs do not need to be unit vectors however they must be non-zero.
930 #[inline]
931 #[must_use]
angle_between(self, rhs: Self) -> f32932 pub fn angle_between(self, rhs: Self) -> f32 {
933 math::acos_approx(
934 self.dot(rhs)
935 .div(math::sqrt(self.length_squared().mul(rhs.length_squared()))),
936 )
937 }
938
939 /// Returns some vector that is orthogonal to the given one.
940 ///
941 /// The input vector must be finite and non-zero.
942 ///
943 /// The output vector is not necessarily unit length. For that use
944 /// [`Self::any_orthonormal_vector()`] instead.
945 #[inline]
946 #[must_use]
any_orthogonal_vector(&self) -> Self947 pub fn any_orthogonal_vector(&self) -> Self {
948 // This can probably be optimized
949 if math::abs(self.x) > math::abs(self.y) {
950 Self::new(-self.z, 0.0, self.x) // self.cross(Self::Y)
951 } else {
952 Self::new(0.0, self.z, -self.y) // self.cross(Self::X)
953 }
954 }
955
956 /// Returns any unit vector that is orthogonal to the given one.
957 ///
958 /// The input vector must be unit length.
959 ///
960 /// # Panics
961 ///
962 /// Will panic if `self` is not normalized when `glam_assert` is enabled.
963 #[inline]
964 #[must_use]
any_orthonormal_vector(&self) -> Self965 pub fn any_orthonormal_vector(&self) -> Self {
966 glam_assert!(self.is_normalized());
967 // From https://graphics.pixar.com/library/OrthonormalB/paper.pdf
968 let sign = math::signum(self.z);
969 let a = -1.0 / (sign + self.z);
970 let b = self.x * self.y * a;
971 Self::new(b, sign + self.y * self.y * a, -self.y)
972 }
973
974 /// Given a unit vector return two other vectors that together form an orthonormal
975 /// basis. That is, all three vectors are orthogonal to each other and are normalized.
976 ///
977 /// # Panics
978 ///
979 /// Will panic if `self` is not normalized when `glam_assert` is enabled.
980 #[inline]
981 #[must_use]
any_orthonormal_pair(&self) -> (Self, Self)982 pub fn any_orthonormal_pair(&self) -> (Self, Self) {
983 glam_assert!(self.is_normalized());
984 // From https://graphics.pixar.com/library/OrthonormalB/paper.pdf
985 let sign = math::signum(self.z);
986 let a = -1.0 / (sign + self.z);
987 let b = self.x * self.y * a;
988 (
989 Self::new(1.0 + sign * self.x * self.x * a, sign * b, -sign * self.x),
990 Self::new(b, sign + self.y * self.y * a, -self.y),
991 )
992 }
993
994 /// Performs a spherical linear interpolation between `self` and `rhs` based on the value `s`.
995 ///
996 /// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result
997 /// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly
998 /// extrapolated.
999 #[inline]
1000 #[must_use]
slerp(self, rhs: Self, s: f32) -> Self1001 pub fn slerp(self, rhs: Self, s: f32) -> Self {
1002 let self_length = self.length();
1003 let rhs_length = rhs.length();
1004 // Cosine of the angle between the vectors [-1, 1], or NaN if either vector has a zero length
1005 let dot = self.dot(rhs) / (self_length * rhs_length);
1006 // If dot is close to 1 or -1, or is NaN the calculations for t1 and t2 break down
1007 if math::abs(dot) < 1.0 - 3e-7 {
1008 // Angle between the vectors [0, +π]
1009 let theta = math::acos_approx(dot);
1010 // Sine of the angle between vectors [0, 1]
1011 let sin_theta = math::sin(theta);
1012 let t1 = math::sin(theta * (1. - s));
1013 let t2 = math::sin(theta * s);
1014
1015 // Interpolate vector lengths
1016 let result_length = self_length.lerp(rhs_length, s);
1017 // Scale the vectors to the target length and interpolate them
1018 return (self * (result_length / self_length) * t1
1019 + rhs * (result_length / rhs_length) * t2)
1020 * sin_theta.recip();
1021 }
1022 if dot < 0.0 {
1023 // Vectors are almost parallel in opposing directions
1024
1025 // Create a rotation from self to rhs along some axis
1026 let axis = self.any_orthogonal_vector().normalize().into();
1027 let rotation = Quat::from_axis_angle(axis, core::f32::consts::PI * s);
1028 // Interpolate vector lengths
1029 let result_length = self_length.lerp(rhs_length, s);
1030 rotation * self * (result_length / self_length)
1031 } else {
1032 // Vectors are almost parallel in the same direction, or dot was NaN
1033 self.lerp(rhs, s)
1034 }
1035 }
1036
1037 /// Casts all elements of `self` to `f64`.
1038 #[inline]
1039 #[must_use]
as_dvec3(&self) -> crate::DVec31040 pub fn as_dvec3(&self) -> crate::DVec3 {
1041 crate::DVec3::new(self.x as f64, self.y as f64, self.z as f64)
1042 }
1043
1044 /// Casts all elements of `self` to `i8`.
1045 #[inline]
1046 #[must_use]
as_i8vec3(&self) -> crate::I8Vec31047 pub fn as_i8vec3(&self) -> crate::I8Vec3 {
1048 crate::I8Vec3::new(self.x as i8, self.y as i8, self.z as i8)
1049 }
1050
1051 /// Casts all elements of `self` to `u8`.
1052 #[inline]
1053 #[must_use]
as_u8vec3(&self) -> crate::U8Vec31054 pub fn as_u8vec3(&self) -> crate::U8Vec3 {
1055 crate::U8Vec3::new(self.x as u8, self.y as u8, self.z as u8)
1056 }
1057
1058 /// Casts all elements of `self` to `i16`.
1059 #[inline]
1060 #[must_use]
as_i16vec3(&self) -> crate::I16Vec31061 pub fn as_i16vec3(&self) -> crate::I16Vec3 {
1062 crate::I16Vec3::new(self.x as i16, self.y as i16, self.z as i16)
1063 }
1064
1065 /// Casts all elements of `self` to `u16`.
1066 #[inline]
1067 #[must_use]
as_u16vec3(&self) -> crate::U16Vec31068 pub fn as_u16vec3(&self) -> crate::U16Vec3 {
1069 crate::U16Vec3::new(self.x as u16, self.y as u16, self.z as u16)
1070 }
1071
1072 /// Casts all elements of `self` to `i32`.
1073 #[inline]
1074 #[must_use]
as_ivec3(&self) -> crate::IVec31075 pub fn as_ivec3(&self) -> crate::IVec3 {
1076 crate::IVec3::new(self.x as i32, self.y as i32, self.z as i32)
1077 }
1078
1079 /// Casts all elements of `self` to `u32`.
1080 #[inline]
1081 #[must_use]
as_uvec3(&self) -> crate::UVec31082 pub fn as_uvec3(&self) -> crate::UVec3 {
1083 crate::UVec3::new(self.x as u32, self.y as u32, self.z as u32)
1084 }
1085
1086 /// Casts all elements of `self` to `i64`.
1087 #[inline]
1088 #[must_use]
as_i64vec3(&self) -> crate::I64Vec31089 pub fn as_i64vec3(&self) -> crate::I64Vec3 {
1090 crate::I64Vec3::new(self.x as i64, self.y as i64, self.z as i64)
1091 }
1092
1093 /// Casts all elements of `self` to `u64`.
1094 #[inline]
1095 #[must_use]
as_u64vec3(&self) -> crate::U64Vec31096 pub fn as_u64vec3(&self) -> crate::U64Vec3 {
1097 crate::U64Vec3::new(self.x as u64, self.y as u64, self.z as u64)
1098 }
1099 }
1100
1101 impl Default for Vec3A {
1102 #[inline(always)]
default() -> Self1103 fn default() -> Self {
1104 Self::ZERO
1105 }
1106 }
1107
1108 impl PartialEq for Vec3A {
1109 #[inline]
eq(&self, rhs: &Self) -> bool1110 fn eq(&self, rhs: &Self) -> bool {
1111 self.cmpeq(*rhs).all()
1112 }
1113 }
1114
1115 impl Div<Vec3A> for Vec3A {
1116 type Output = Self;
1117 #[inline]
div(self, rhs: Self) -> Self1118 fn div(self, rhs: Self) -> Self {
1119 Self(unsafe { _mm_div_ps(self.0, rhs.0) })
1120 }
1121 }
1122
1123 impl Div<&Vec3A> for Vec3A {
1124 type Output = Vec3A;
1125 #[inline]
div(self, rhs: &Vec3A) -> Vec3A1126 fn div(self, rhs: &Vec3A) -> Vec3A {
1127 self.div(*rhs)
1128 }
1129 }
1130
1131 impl Div<&Vec3A> for &Vec3A {
1132 type Output = Vec3A;
1133 #[inline]
div(self, rhs: &Vec3A) -> Vec3A1134 fn div(self, rhs: &Vec3A) -> Vec3A {
1135 (*self).div(*rhs)
1136 }
1137 }
1138
1139 impl Div<Vec3A> for &Vec3A {
1140 type Output = Vec3A;
1141 #[inline]
div(self, rhs: Vec3A) -> Vec3A1142 fn div(self, rhs: Vec3A) -> Vec3A {
1143 (*self).div(rhs)
1144 }
1145 }
1146
1147 impl DivAssign<Vec3A> for Vec3A {
1148 #[inline]
div_assign(&mut self, rhs: Self)1149 fn div_assign(&mut self, rhs: Self) {
1150 self.0 = unsafe { _mm_div_ps(self.0, rhs.0) };
1151 }
1152 }
1153
1154 impl DivAssign<&Vec3A> for Vec3A {
1155 #[inline]
div_assign(&mut self, rhs: &Vec3A)1156 fn div_assign(&mut self, rhs: &Vec3A) {
1157 self.div_assign(*rhs)
1158 }
1159 }
1160
1161 impl Div<f32> for Vec3A {
1162 type Output = Self;
1163 #[inline]
div(self, rhs: f32) -> Self1164 fn div(self, rhs: f32) -> Self {
1165 Self(unsafe { _mm_div_ps(self.0, _mm_set1_ps(rhs)) })
1166 }
1167 }
1168
1169 impl Div<&f32> for Vec3A {
1170 type Output = Vec3A;
1171 #[inline]
div(self, rhs: &f32) -> Vec3A1172 fn div(self, rhs: &f32) -> Vec3A {
1173 self.div(*rhs)
1174 }
1175 }
1176
1177 impl Div<&f32> for &Vec3A {
1178 type Output = Vec3A;
1179 #[inline]
div(self, rhs: &f32) -> Vec3A1180 fn div(self, rhs: &f32) -> Vec3A {
1181 (*self).div(*rhs)
1182 }
1183 }
1184
1185 impl Div<f32> for &Vec3A {
1186 type Output = Vec3A;
1187 #[inline]
div(self, rhs: f32) -> Vec3A1188 fn div(self, rhs: f32) -> Vec3A {
1189 (*self).div(rhs)
1190 }
1191 }
1192
1193 impl DivAssign<f32> for Vec3A {
1194 #[inline]
div_assign(&mut self, rhs: f32)1195 fn div_assign(&mut self, rhs: f32) {
1196 self.0 = unsafe { _mm_div_ps(self.0, _mm_set1_ps(rhs)) };
1197 }
1198 }
1199
1200 impl DivAssign<&f32> for Vec3A {
1201 #[inline]
div_assign(&mut self, rhs: &f32)1202 fn div_assign(&mut self, rhs: &f32) {
1203 self.div_assign(*rhs)
1204 }
1205 }
1206
1207 impl Div<Vec3A> for f32 {
1208 type Output = Vec3A;
1209 #[inline]
div(self, rhs: Vec3A) -> Vec3A1210 fn div(self, rhs: Vec3A) -> Vec3A {
1211 Vec3A(unsafe { _mm_div_ps(_mm_set1_ps(self), rhs.0) })
1212 }
1213 }
1214
1215 impl Div<&Vec3A> for f32 {
1216 type Output = Vec3A;
1217 #[inline]
div(self, rhs: &Vec3A) -> Vec3A1218 fn div(self, rhs: &Vec3A) -> Vec3A {
1219 self.div(*rhs)
1220 }
1221 }
1222
1223 impl Div<&Vec3A> for &f32 {
1224 type Output = Vec3A;
1225 #[inline]
div(self, rhs: &Vec3A) -> Vec3A1226 fn div(self, rhs: &Vec3A) -> Vec3A {
1227 (*self).div(*rhs)
1228 }
1229 }
1230
1231 impl Div<Vec3A> for &f32 {
1232 type Output = Vec3A;
1233 #[inline]
div(self, rhs: Vec3A) -> Vec3A1234 fn div(self, rhs: Vec3A) -> Vec3A {
1235 (*self).div(rhs)
1236 }
1237 }
1238
1239 impl Mul<Vec3A> for Vec3A {
1240 type Output = Self;
1241 #[inline]
mul(self, rhs: Self) -> Self1242 fn mul(self, rhs: Self) -> Self {
1243 Self(unsafe { _mm_mul_ps(self.0, rhs.0) })
1244 }
1245 }
1246
1247 impl Mul<&Vec3A> for Vec3A {
1248 type Output = Vec3A;
1249 #[inline]
mul(self, rhs: &Vec3A) -> Vec3A1250 fn mul(self, rhs: &Vec3A) -> Vec3A {
1251 self.mul(*rhs)
1252 }
1253 }
1254
1255 impl Mul<&Vec3A> for &Vec3A {
1256 type Output = Vec3A;
1257 #[inline]
mul(self, rhs: &Vec3A) -> Vec3A1258 fn mul(self, rhs: &Vec3A) -> Vec3A {
1259 (*self).mul(*rhs)
1260 }
1261 }
1262
1263 impl Mul<Vec3A> for &Vec3A {
1264 type Output = Vec3A;
1265 #[inline]
mul(self, rhs: Vec3A) -> Vec3A1266 fn mul(self, rhs: Vec3A) -> Vec3A {
1267 (*self).mul(rhs)
1268 }
1269 }
1270
1271 impl MulAssign<Vec3A> for Vec3A {
1272 #[inline]
mul_assign(&mut self, rhs: Self)1273 fn mul_assign(&mut self, rhs: Self) {
1274 self.0 = unsafe { _mm_mul_ps(self.0, rhs.0) };
1275 }
1276 }
1277
1278 impl MulAssign<&Vec3A> for Vec3A {
1279 #[inline]
mul_assign(&mut self, rhs: &Vec3A)1280 fn mul_assign(&mut self, rhs: &Vec3A) {
1281 self.mul_assign(*rhs)
1282 }
1283 }
1284
1285 impl Mul<f32> for Vec3A {
1286 type Output = Self;
1287 #[inline]
mul(self, rhs: f32) -> Self1288 fn mul(self, rhs: f32) -> Self {
1289 Self(unsafe { _mm_mul_ps(self.0, _mm_set1_ps(rhs)) })
1290 }
1291 }
1292
1293 impl Mul<&f32> for Vec3A {
1294 type Output = Vec3A;
1295 #[inline]
mul(self, rhs: &f32) -> Vec3A1296 fn mul(self, rhs: &f32) -> Vec3A {
1297 self.mul(*rhs)
1298 }
1299 }
1300
1301 impl Mul<&f32> for &Vec3A {
1302 type Output = Vec3A;
1303 #[inline]
mul(self, rhs: &f32) -> Vec3A1304 fn mul(self, rhs: &f32) -> Vec3A {
1305 (*self).mul(*rhs)
1306 }
1307 }
1308
1309 impl Mul<f32> for &Vec3A {
1310 type Output = Vec3A;
1311 #[inline]
mul(self, rhs: f32) -> Vec3A1312 fn mul(self, rhs: f32) -> Vec3A {
1313 (*self).mul(rhs)
1314 }
1315 }
1316
1317 impl MulAssign<f32> for Vec3A {
1318 #[inline]
mul_assign(&mut self, rhs: f32)1319 fn mul_assign(&mut self, rhs: f32) {
1320 self.0 = unsafe { _mm_mul_ps(self.0, _mm_set1_ps(rhs)) };
1321 }
1322 }
1323
1324 impl MulAssign<&f32> for Vec3A {
1325 #[inline]
mul_assign(&mut self, rhs: &f32)1326 fn mul_assign(&mut self, rhs: &f32) {
1327 self.mul_assign(*rhs)
1328 }
1329 }
1330
1331 impl Mul<Vec3A> for f32 {
1332 type Output = Vec3A;
1333 #[inline]
mul(self, rhs: Vec3A) -> Vec3A1334 fn mul(self, rhs: Vec3A) -> Vec3A {
1335 Vec3A(unsafe { _mm_mul_ps(_mm_set1_ps(self), rhs.0) })
1336 }
1337 }
1338
1339 impl Mul<&Vec3A> for f32 {
1340 type Output = Vec3A;
1341 #[inline]
mul(self, rhs: &Vec3A) -> Vec3A1342 fn mul(self, rhs: &Vec3A) -> Vec3A {
1343 self.mul(*rhs)
1344 }
1345 }
1346
1347 impl Mul<&Vec3A> for &f32 {
1348 type Output = Vec3A;
1349 #[inline]
mul(self, rhs: &Vec3A) -> Vec3A1350 fn mul(self, rhs: &Vec3A) -> Vec3A {
1351 (*self).mul(*rhs)
1352 }
1353 }
1354
1355 impl Mul<Vec3A> for &f32 {
1356 type Output = Vec3A;
1357 #[inline]
mul(self, rhs: Vec3A) -> Vec3A1358 fn mul(self, rhs: Vec3A) -> Vec3A {
1359 (*self).mul(rhs)
1360 }
1361 }
1362
1363 impl Add<Vec3A> for Vec3A {
1364 type Output = Self;
1365 #[inline]
add(self, rhs: Self) -> Self1366 fn add(self, rhs: Self) -> Self {
1367 Self(unsafe { _mm_add_ps(self.0, rhs.0) })
1368 }
1369 }
1370
1371 impl Add<&Vec3A> for Vec3A {
1372 type Output = Vec3A;
1373 #[inline]
add(self, rhs: &Vec3A) -> Vec3A1374 fn add(self, rhs: &Vec3A) -> Vec3A {
1375 self.add(*rhs)
1376 }
1377 }
1378
1379 impl Add<&Vec3A> for &Vec3A {
1380 type Output = Vec3A;
1381 #[inline]
add(self, rhs: &Vec3A) -> Vec3A1382 fn add(self, rhs: &Vec3A) -> Vec3A {
1383 (*self).add(*rhs)
1384 }
1385 }
1386
1387 impl Add<Vec3A> for &Vec3A {
1388 type Output = Vec3A;
1389 #[inline]
add(self, rhs: Vec3A) -> Vec3A1390 fn add(self, rhs: Vec3A) -> Vec3A {
1391 (*self).add(rhs)
1392 }
1393 }
1394
1395 impl AddAssign<Vec3A> for Vec3A {
1396 #[inline]
add_assign(&mut self, rhs: Self)1397 fn add_assign(&mut self, rhs: Self) {
1398 self.0 = unsafe { _mm_add_ps(self.0, rhs.0) };
1399 }
1400 }
1401
1402 impl AddAssign<&Vec3A> for Vec3A {
1403 #[inline]
add_assign(&mut self, rhs: &Vec3A)1404 fn add_assign(&mut self, rhs: &Vec3A) {
1405 self.add_assign(*rhs)
1406 }
1407 }
1408
1409 impl Add<f32> for Vec3A {
1410 type Output = Self;
1411 #[inline]
add(self, rhs: f32) -> Self1412 fn add(self, rhs: f32) -> Self {
1413 Self(unsafe { _mm_add_ps(self.0, _mm_set1_ps(rhs)) })
1414 }
1415 }
1416
1417 impl Add<&f32> for Vec3A {
1418 type Output = Vec3A;
1419 #[inline]
add(self, rhs: &f32) -> Vec3A1420 fn add(self, rhs: &f32) -> Vec3A {
1421 self.add(*rhs)
1422 }
1423 }
1424
1425 impl Add<&f32> for &Vec3A {
1426 type Output = Vec3A;
1427 #[inline]
add(self, rhs: &f32) -> Vec3A1428 fn add(self, rhs: &f32) -> Vec3A {
1429 (*self).add(*rhs)
1430 }
1431 }
1432
1433 impl Add<f32> for &Vec3A {
1434 type Output = Vec3A;
1435 #[inline]
add(self, rhs: f32) -> Vec3A1436 fn add(self, rhs: f32) -> Vec3A {
1437 (*self).add(rhs)
1438 }
1439 }
1440
1441 impl AddAssign<f32> for Vec3A {
1442 #[inline]
add_assign(&mut self, rhs: f32)1443 fn add_assign(&mut self, rhs: f32) {
1444 self.0 = unsafe { _mm_add_ps(self.0, _mm_set1_ps(rhs)) };
1445 }
1446 }
1447
1448 impl AddAssign<&f32> for Vec3A {
1449 #[inline]
add_assign(&mut self, rhs: &f32)1450 fn add_assign(&mut self, rhs: &f32) {
1451 self.add_assign(*rhs)
1452 }
1453 }
1454
1455 impl Add<Vec3A> for f32 {
1456 type Output = Vec3A;
1457 #[inline]
add(self, rhs: Vec3A) -> Vec3A1458 fn add(self, rhs: Vec3A) -> Vec3A {
1459 Vec3A(unsafe { _mm_add_ps(_mm_set1_ps(self), rhs.0) })
1460 }
1461 }
1462
1463 impl Add<&Vec3A> for f32 {
1464 type Output = Vec3A;
1465 #[inline]
add(self, rhs: &Vec3A) -> Vec3A1466 fn add(self, rhs: &Vec3A) -> Vec3A {
1467 self.add(*rhs)
1468 }
1469 }
1470
1471 impl Add<&Vec3A> for &f32 {
1472 type Output = Vec3A;
1473 #[inline]
add(self, rhs: &Vec3A) -> Vec3A1474 fn add(self, rhs: &Vec3A) -> Vec3A {
1475 (*self).add(*rhs)
1476 }
1477 }
1478
1479 impl Add<Vec3A> for &f32 {
1480 type Output = Vec3A;
1481 #[inline]
add(self, rhs: Vec3A) -> Vec3A1482 fn add(self, rhs: Vec3A) -> Vec3A {
1483 (*self).add(rhs)
1484 }
1485 }
1486
1487 impl Sub<Vec3A> for Vec3A {
1488 type Output = Self;
1489 #[inline]
sub(self, rhs: Self) -> Self1490 fn sub(self, rhs: Self) -> Self {
1491 Self(unsafe { _mm_sub_ps(self.0, rhs.0) })
1492 }
1493 }
1494
1495 impl Sub<&Vec3A> for Vec3A {
1496 type Output = Vec3A;
1497 #[inline]
sub(self, rhs: &Vec3A) -> Vec3A1498 fn sub(self, rhs: &Vec3A) -> Vec3A {
1499 self.sub(*rhs)
1500 }
1501 }
1502
1503 impl Sub<&Vec3A> for &Vec3A {
1504 type Output = Vec3A;
1505 #[inline]
sub(self, rhs: &Vec3A) -> Vec3A1506 fn sub(self, rhs: &Vec3A) -> Vec3A {
1507 (*self).sub(*rhs)
1508 }
1509 }
1510
1511 impl Sub<Vec3A> for &Vec3A {
1512 type Output = Vec3A;
1513 #[inline]
sub(self, rhs: Vec3A) -> Vec3A1514 fn sub(self, rhs: Vec3A) -> Vec3A {
1515 (*self).sub(rhs)
1516 }
1517 }
1518
1519 impl SubAssign<Vec3A> for Vec3A {
1520 #[inline]
sub_assign(&mut self, rhs: Vec3A)1521 fn sub_assign(&mut self, rhs: Vec3A) {
1522 self.0 = unsafe { _mm_sub_ps(self.0, rhs.0) };
1523 }
1524 }
1525
1526 impl SubAssign<&Vec3A> for Vec3A {
1527 #[inline]
sub_assign(&mut self, rhs: &Vec3A)1528 fn sub_assign(&mut self, rhs: &Vec3A) {
1529 self.sub_assign(*rhs)
1530 }
1531 }
1532
1533 impl Sub<f32> for Vec3A {
1534 type Output = Self;
1535 #[inline]
sub(self, rhs: f32) -> Self1536 fn sub(self, rhs: f32) -> Self {
1537 Self(unsafe { _mm_sub_ps(self.0, _mm_set1_ps(rhs)) })
1538 }
1539 }
1540
1541 impl Sub<&f32> for Vec3A {
1542 type Output = Vec3A;
1543 #[inline]
sub(self, rhs: &f32) -> Vec3A1544 fn sub(self, rhs: &f32) -> Vec3A {
1545 self.sub(*rhs)
1546 }
1547 }
1548
1549 impl Sub<&f32> for &Vec3A {
1550 type Output = Vec3A;
1551 #[inline]
sub(self, rhs: &f32) -> Vec3A1552 fn sub(self, rhs: &f32) -> Vec3A {
1553 (*self).sub(*rhs)
1554 }
1555 }
1556
1557 impl Sub<f32> for &Vec3A {
1558 type Output = Vec3A;
1559 #[inline]
sub(self, rhs: f32) -> Vec3A1560 fn sub(self, rhs: f32) -> Vec3A {
1561 (*self).sub(rhs)
1562 }
1563 }
1564
1565 impl SubAssign<f32> for Vec3A {
1566 #[inline]
sub_assign(&mut self, rhs: f32)1567 fn sub_assign(&mut self, rhs: f32) {
1568 self.0 = unsafe { _mm_sub_ps(self.0, _mm_set1_ps(rhs)) };
1569 }
1570 }
1571
1572 impl SubAssign<&f32> for Vec3A {
1573 #[inline]
sub_assign(&mut self, rhs: &f32)1574 fn sub_assign(&mut self, rhs: &f32) {
1575 self.sub_assign(*rhs)
1576 }
1577 }
1578
1579 impl Sub<Vec3A> for f32 {
1580 type Output = Vec3A;
1581 #[inline]
sub(self, rhs: Vec3A) -> Vec3A1582 fn sub(self, rhs: Vec3A) -> Vec3A {
1583 Vec3A(unsafe { _mm_sub_ps(_mm_set1_ps(self), rhs.0) })
1584 }
1585 }
1586
1587 impl Sub<&Vec3A> for f32 {
1588 type Output = Vec3A;
1589 #[inline]
sub(self, rhs: &Vec3A) -> Vec3A1590 fn sub(self, rhs: &Vec3A) -> Vec3A {
1591 self.sub(*rhs)
1592 }
1593 }
1594
1595 impl Sub<&Vec3A> for &f32 {
1596 type Output = Vec3A;
1597 #[inline]
sub(self, rhs: &Vec3A) -> Vec3A1598 fn sub(self, rhs: &Vec3A) -> Vec3A {
1599 (*self).sub(*rhs)
1600 }
1601 }
1602
1603 impl Sub<Vec3A> for &f32 {
1604 type Output = Vec3A;
1605 #[inline]
sub(self, rhs: Vec3A) -> Vec3A1606 fn sub(self, rhs: Vec3A) -> Vec3A {
1607 (*self).sub(rhs)
1608 }
1609 }
1610
1611 impl Rem<Vec3A> for Vec3A {
1612 type Output = Self;
1613 #[inline]
rem(self, rhs: Self) -> Self1614 fn rem(self, rhs: Self) -> Self {
1615 unsafe {
1616 let n = m128_floor(_mm_div_ps(self.0, rhs.0));
1617 Self(_mm_sub_ps(self.0, _mm_mul_ps(n, rhs.0)))
1618 }
1619 }
1620 }
1621
1622 impl Rem<&Vec3A> for Vec3A {
1623 type Output = Vec3A;
1624 #[inline]
rem(self, rhs: &Vec3A) -> Vec3A1625 fn rem(self, rhs: &Vec3A) -> Vec3A {
1626 self.rem(*rhs)
1627 }
1628 }
1629
1630 impl Rem<&Vec3A> for &Vec3A {
1631 type Output = Vec3A;
1632 #[inline]
rem(self, rhs: &Vec3A) -> Vec3A1633 fn rem(self, rhs: &Vec3A) -> Vec3A {
1634 (*self).rem(*rhs)
1635 }
1636 }
1637
1638 impl Rem<Vec3A> for &Vec3A {
1639 type Output = Vec3A;
1640 #[inline]
rem(self, rhs: Vec3A) -> Vec3A1641 fn rem(self, rhs: Vec3A) -> Vec3A {
1642 (*self).rem(rhs)
1643 }
1644 }
1645
1646 impl RemAssign<Vec3A> for Vec3A {
1647 #[inline]
rem_assign(&mut self, rhs: Self)1648 fn rem_assign(&mut self, rhs: Self) {
1649 *self = self.rem(rhs);
1650 }
1651 }
1652
1653 impl RemAssign<&Vec3A> for Vec3A {
1654 #[inline]
rem_assign(&mut self, rhs: &Vec3A)1655 fn rem_assign(&mut self, rhs: &Vec3A) {
1656 self.rem_assign(*rhs)
1657 }
1658 }
1659
1660 impl Rem<f32> for Vec3A {
1661 type Output = Self;
1662 #[inline]
rem(self, rhs: f32) -> Self1663 fn rem(self, rhs: f32) -> Self {
1664 self.rem(Self::splat(rhs))
1665 }
1666 }
1667
1668 impl Rem<&f32> for Vec3A {
1669 type Output = Vec3A;
1670 #[inline]
rem(self, rhs: &f32) -> Vec3A1671 fn rem(self, rhs: &f32) -> Vec3A {
1672 self.rem(*rhs)
1673 }
1674 }
1675
1676 impl Rem<&f32> for &Vec3A {
1677 type Output = Vec3A;
1678 #[inline]
rem(self, rhs: &f32) -> Vec3A1679 fn rem(self, rhs: &f32) -> Vec3A {
1680 (*self).rem(*rhs)
1681 }
1682 }
1683
1684 impl Rem<f32> for &Vec3A {
1685 type Output = Vec3A;
1686 #[inline]
rem(self, rhs: f32) -> Vec3A1687 fn rem(self, rhs: f32) -> Vec3A {
1688 (*self).rem(rhs)
1689 }
1690 }
1691
1692 impl RemAssign<f32> for Vec3A {
1693 #[inline]
rem_assign(&mut self, rhs: f32)1694 fn rem_assign(&mut self, rhs: f32) {
1695 *self = self.rem(Self::splat(rhs));
1696 }
1697 }
1698
1699 impl RemAssign<&f32> for Vec3A {
1700 #[inline]
rem_assign(&mut self, rhs: &f32)1701 fn rem_assign(&mut self, rhs: &f32) {
1702 self.rem_assign(*rhs)
1703 }
1704 }
1705
1706 impl Rem<Vec3A> for f32 {
1707 type Output = Vec3A;
1708 #[inline]
rem(self, rhs: Vec3A) -> Vec3A1709 fn rem(self, rhs: Vec3A) -> Vec3A {
1710 Vec3A::splat(self).rem(rhs)
1711 }
1712 }
1713
1714 impl Rem<&Vec3A> for f32 {
1715 type Output = Vec3A;
1716 #[inline]
rem(self, rhs: &Vec3A) -> Vec3A1717 fn rem(self, rhs: &Vec3A) -> Vec3A {
1718 self.rem(*rhs)
1719 }
1720 }
1721
1722 impl Rem<&Vec3A> for &f32 {
1723 type Output = Vec3A;
1724 #[inline]
rem(self, rhs: &Vec3A) -> Vec3A1725 fn rem(self, rhs: &Vec3A) -> Vec3A {
1726 (*self).rem(*rhs)
1727 }
1728 }
1729
1730 impl Rem<Vec3A> for &f32 {
1731 type Output = Vec3A;
1732 #[inline]
rem(self, rhs: Vec3A) -> Vec3A1733 fn rem(self, rhs: Vec3A) -> Vec3A {
1734 (*self).rem(rhs)
1735 }
1736 }
1737
1738 #[cfg(not(target_arch = "spirv"))]
1739 impl AsRef<[f32; 3]> for Vec3A {
1740 #[inline]
as_ref(&self) -> &[f32; 3]1741 fn as_ref(&self) -> &[f32; 3] {
1742 unsafe { &*(self as *const Vec3A as *const [f32; 3]) }
1743 }
1744 }
1745
1746 #[cfg(not(target_arch = "spirv"))]
1747 impl AsMut<[f32; 3]> for Vec3A {
1748 #[inline]
as_mut(&mut self) -> &mut [f32; 3]1749 fn as_mut(&mut self) -> &mut [f32; 3] {
1750 unsafe { &mut *(self as *mut Vec3A as *mut [f32; 3]) }
1751 }
1752 }
1753
1754 impl Sum for Vec3A {
1755 #[inline]
sum<I>(iter: I) -> Self where I: Iterator<Item = Self>,1756 fn sum<I>(iter: I) -> Self
1757 where
1758 I: Iterator<Item = Self>,
1759 {
1760 iter.fold(Self::ZERO, Self::add)
1761 }
1762 }
1763
1764 impl<'a> Sum<&'a Self> for Vec3A {
1765 #[inline]
sum<I>(iter: I) -> Self where I: Iterator<Item = &'a Self>,1766 fn sum<I>(iter: I) -> Self
1767 where
1768 I: Iterator<Item = &'a Self>,
1769 {
1770 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
1771 }
1772 }
1773
1774 impl Product for Vec3A {
1775 #[inline]
product<I>(iter: I) -> Self where I: Iterator<Item = Self>,1776 fn product<I>(iter: I) -> Self
1777 where
1778 I: Iterator<Item = Self>,
1779 {
1780 iter.fold(Self::ONE, Self::mul)
1781 }
1782 }
1783
1784 impl<'a> Product<&'a Self> for Vec3A {
1785 #[inline]
product<I>(iter: I) -> Self where I: Iterator<Item = &'a Self>,1786 fn product<I>(iter: I) -> Self
1787 where
1788 I: Iterator<Item = &'a Self>,
1789 {
1790 iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
1791 }
1792 }
1793
1794 impl Neg for Vec3A {
1795 type Output = Self;
1796 #[inline]
neg(self) -> Self1797 fn neg(self) -> Self {
1798 Self(unsafe { _mm_xor_ps(_mm_set1_ps(-0.0), self.0) })
1799 }
1800 }
1801
1802 impl Neg for &Vec3A {
1803 type Output = Vec3A;
1804 #[inline]
neg(self) -> Vec3A1805 fn neg(self) -> Vec3A {
1806 (*self).neg()
1807 }
1808 }
1809
1810 impl Index<usize> for Vec3A {
1811 type Output = f32;
1812 #[inline]
index(&self, index: usize) -> &Self::Output1813 fn index(&self, index: usize) -> &Self::Output {
1814 match index {
1815 0 => &self.x,
1816 1 => &self.y,
1817 2 => &self.z,
1818 _ => panic!("index out of bounds"),
1819 }
1820 }
1821 }
1822
1823 impl IndexMut<usize> for Vec3A {
1824 #[inline]
index_mut(&mut self, index: usize) -> &mut Self::Output1825 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1826 match index {
1827 0 => &mut self.x,
1828 1 => &mut self.y,
1829 2 => &mut self.z,
1830 _ => panic!("index out of bounds"),
1831 }
1832 }
1833 }
1834
1835 impl fmt::Display for Vec3A {
fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result1836 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1837 if let Some(p) = f.precision() {
1838 write!(f, "[{:.*}, {:.*}, {:.*}]", p, self.x, p, self.y, p, self.z)
1839 } else {
1840 write!(f, "[{}, {}, {}]", self.x, self.y, self.z)
1841 }
1842 }
1843 }
1844
1845 impl fmt::Debug for Vec3A {
fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result1846 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1847 fmt.debug_tuple(stringify!(Vec3A))
1848 .field(&self.x)
1849 .field(&self.y)
1850 .field(&self.z)
1851 .finish()
1852 }
1853 }
1854
1855 impl From<Vec3A> for __m128 {
1856 #[inline(always)]
from(t: Vec3A) -> Self1857 fn from(t: Vec3A) -> Self {
1858 t.0
1859 }
1860 }
1861
1862 impl From<__m128> for Vec3A {
1863 #[inline(always)]
from(t: __m128) -> Self1864 fn from(t: __m128) -> Self {
1865 Self(t)
1866 }
1867 }
1868
1869 impl From<[f32; 3]> for Vec3A {
1870 #[inline]
from(a: [f32; 3]) -> Self1871 fn from(a: [f32; 3]) -> Self {
1872 Self::new(a[0], a[1], a[2])
1873 }
1874 }
1875
1876 impl From<Vec3A> for [f32; 3] {
1877 #[inline]
from(v: Vec3A) -> Self1878 fn from(v: Vec3A) -> Self {
1879 use crate::Align16;
1880 use core::mem::MaybeUninit;
1881 let mut out: MaybeUninit<Align16<Self>> = MaybeUninit::uninit();
1882 unsafe {
1883 _mm_store_ps(out.as_mut_ptr().cast(), v.0);
1884 out.assume_init().0
1885 }
1886 }
1887 }
1888
1889 impl From<(f32, f32, f32)> for Vec3A {
1890 #[inline]
from(t: (f32, f32, f32)) -> Self1891 fn from(t: (f32, f32, f32)) -> Self {
1892 Self::new(t.0, t.1, t.2)
1893 }
1894 }
1895
1896 impl From<Vec3A> for (f32, f32, f32) {
1897 #[inline]
from(v: Vec3A) -> Self1898 fn from(v: Vec3A) -> Self {
1899 use crate::Align16;
1900 use core::mem::MaybeUninit;
1901 let mut out: MaybeUninit<Align16<Self>> = MaybeUninit::uninit();
1902 unsafe {
1903 _mm_store_ps(out.as_mut_ptr().cast(), v.0);
1904 out.assume_init().0
1905 }
1906 }
1907 }
1908
1909 impl From<Vec3> for Vec3A {
1910 #[inline]
from(v: Vec3) -> Self1911 fn from(v: Vec3) -> Self {
1912 Self::new(v.x, v.y, v.z)
1913 }
1914 }
1915
1916 impl From<Vec3A> for Vec3 {
1917 #[inline]
from(v: Vec3A) -> Self1918 fn from(v: Vec3A) -> Self {
1919 use crate::Align16;
1920 use core::mem::MaybeUninit;
1921 let mut out: MaybeUninit<Align16<Self>> = MaybeUninit::uninit();
1922 unsafe {
1923 _mm_store_ps(out.as_mut_ptr().cast(), v.0);
1924 out.assume_init().0
1925 }
1926 }
1927 }
1928
1929 impl From<(Vec2, f32)> for Vec3A {
1930 #[inline]
from((v, z): (Vec2, f32)) -> Self1931 fn from((v, z): (Vec2, f32)) -> Self {
1932 Self::new(v.x, v.y, z)
1933 }
1934 }
1935
1936 impl Deref for Vec3A {
1937 type Target = crate::deref::Vec3<f32>;
1938 #[inline]
deref(&self) -> &Self::Target1939 fn deref(&self) -> &Self::Target {
1940 unsafe { &*(self as *const Self).cast() }
1941 }
1942 }
1943
1944 impl DerefMut for Vec3A {
1945 #[inline]
deref_mut(&mut self) -> &mut Self::Target1946 fn deref_mut(&mut self) -> &mut Self::Target {
1947 unsafe { &mut *(self as *mut Self).cast() }
1948 }
1949 }
1950
1951 impl From<BVec3> for Vec3A {
1952 #[inline]
from(v: BVec3) -> Self1953 fn from(v: BVec3) -> Self {
1954 Self::new(f32::from(v.x), f32::from(v.y), f32::from(v.z))
1955 }
1956 }
1957
1958 impl From<BVec3A> for Vec3A {
1959 #[inline]
from(v: BVec3A) -> Self1960 fn from(v: BVec3A) -> Self {
1961 let bool_array: [bool; 3] = v.into();
1962 Self::new(
1963 f32::from(bool_array[0]),
1964 f32::from(bool_array[1]),
1965 f32::from(bool_array[2]),
1966 )
1967 }
1968 }
1969