Debian Codegraph @

debian/missing-sources/glam-0.28.0/src/f32/sse2/vec3a.rs

raw symbols SCIP
1 // Generated from vec.rs.tera template. Edit the template, not the generated file.
2
3 use crate::{f32::math, sse2::*, BVec3, BVec3A, Vec2, Vec3, Vec4};
4
5 #[cfg(not(target_arch = "spirv"))]
6 use core::fmt;
7 use core::iter::{Product, Sum};
8 use core::{f32, ops::*};
9
10 #[cfg(target_arch = "x86")]
11 use core::arch::x86::*;
12 #[cfg(target_arch = "x86_64")]
13 use core::arch::x86_64::*;
14
15 #[repr(C)]
16 union UnionCast {
17 a: [f32; 4],
18 v: Vec3A,
19 }
20
21 /// Creates a 3-dimensional vector.
22 #[inline(always)]
23 #[must_use]
24 pub const fn vec3a(x: f32, y: f32, z: f32) -> Vec3A {
25 Vec3A::new(x, y, z)
26 }
27
28 /// A 3-dimensional vector.
29 ///
30 /// SIMD vector types are used for storage on supported platforms for better
31 /// performance than the [`Vec3`] type.
32 ///
33 /// It is possible to convert between [`Vec3`] and [`Vec3A`] types using [`From`]
34 /// or [`Into`] trait implementations.
35 ///
36 /// This type is 16 byte aligned.
37 #[derive(Clone, Copy)]
38 #[repr(transparent)]
39 pub struct Vec3A(pub(crate) __m128);
40
41 impl Vec3A {
42 /// All zeroes.
43 pub const ZERO: Self = Self::splat(0.0);
44
45 /// All ones.
46 pub const ONE: Self = Self::splat(1.0);
47
48 /// All negative ones.
49 pub const NEG_ONE: Self = Self::splat(-1.0);
50
51 /// All `f32::MIN`.
52 pub const MIN: Self = Self::splat(f32::MIN);
53
54 /// All `f32::MAX`.
55 pub const MAX: Self = Self::splat(f32::MAX);
56
57 /// All `f32::NAN`.
58 pub const NAN: Self = Self::splat(f32::NAN);
59
60 /// All `f32::INFINITY`.
61 pub const INFINITY: Self = Self::splat(f32::INFINITY);
62
63 /// All `f32::NEG_INFINITY`.
64 pub const NEG_INFINITY: Self = Self::splat(f32::NEG_INFINITY);
65
66 /// A unit vector pointing along the positive X axis.
67 pub const X: Self = Self::new(1.0, 0.0, 0.0);
68
69 /// A unit vector pointing along the positive Y axis.
70 pub const Y: Self = Self::new(0.0, 1.0, 0.0);
71
72 /// A unit vector pointing along the positive Z axis.
73 pub const Z: Self = Self::new(0.0, 0.0, 1.0);
74
75 /// A unit vector pointing along the negative X axis.
76 pub const NEG_X: Self = Self::new(-1.0, 0.0, 0.0);
77
78 /// A unit vector pointing along the negative Y axis.
79 pub const NEG_Y: Self = Self::new(0.0, -1.0, 0.0);
80
81 /// A unit vector pointing along the negative Z axis.
82 pub const NEG_Z: Self = Self::new(0.0, 0.0, -1.0);
83
84 /// The unit axes.
85 pub const AXES: [Self; 3] = [Self::X, Self::Y, Self::Z];
86
87 /// Creates a new vector.
88 #[inline(always)]
89 #[must_use]
90 pub const fn new(x: f32, y: f32, z: f32) -> Self {
91 unsafe { UnionCast { a: [x, y, z, z] }.v }
92 }
93
94 /// Creates a vector with all elements set to `v`.
95 #[inline]
96 #[must_use]
97 pub const fn splat(v: f32) -> Self {
98 unsafe { UnionCast { a: [v; 4] }.v }
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]
108 pub fn select(mask: BVec3A, if_true: Self, if_false: Self) -> Self {
109 Self(unsafe {
110 _mm_or_ps(
111 _mm_andnot_ps(mask.0, if_false.0),
112 _mm_and_ps(if_true.0, mask.0),
113 )
114 })
115 }
116
117 /// Creates a new vector from an array.
118 #[inline]
119 #[must_use]
120 pub const fn from_array(a: [f32; 3]) -> Self {
121 Self::new(a[0], a[1], a[2])
122 }
123
124 /// `[x, y, z]`
125 #[inline]
126 #[must_use]
127 pub const fn to_array(&self) -> [f32; 3] {
128 unsafe { *(self as *const Vec3A as *const [f32; 3]) }
129 }
130
131 /// Creates a vector from the first 3 values in `slice`.
132 ///
133 /// # Panics
134 ///
135 /// Panics if `slice` is less than 3 elements long.
136 #[inline]
137 #[must_use]
138 pub const fn from_slice(slice: &[f32]) -> Self {
139 Self::new(slice[0], slice[1], slice[2])
140 }
141
142 /// Writes the elements of `self` to the first 3 elements in `slice`.
143 ///
144 /// # Panics
145 ///
146 /// Panics if `slice` is less than 3 elements long.
147 #[inline]
148 pub fn write_to_slice(self, slice: &mut [f32]) {
149 slice[0] = self.x;
150 slice[1] = self.y;
151 slice[2] = self.z;
152 }
153
154 /// Creates a [`Vec3A`] from the `x`, `y` and `z` elements of `self` discarding `w`.
155 ///
156 /// On architectures where SIMD is supported such as SSE2 on `x86_64` this conversion is a noop.
157 #[inline]
158 #[must_use]
159 pub fn from_vec4(v: Vec4) -> Self {
160 Self(v.0)
161 }
162
163 /// Creates a 4D vector from `self` and the given `w` value.
164 #[inline]
165 #[must_use]
166 pub fn extend(self, w: f32) -> Vec4 {
167 Vec4::new(self.x, self.y, self.z, w)
168 }
169
170 /// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`.
171 ///
172 /// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()].
173 #[inline]
174 #[must_use]
175 pub fn truncate(self) -> Vec2 {
176 use crate::swizzles::Vec3Swizzles;
177 self.xy()
178 }
179
180 /// Creates a 3D vector from `self` with the given value of `x`.
181 #[inline]
182 #[must_use]
183 pub fn with_x(mut self, x: f32) -> Self {
184 self.x = x;
185 self
186 }
187
188 /// Creates a 3D vector from `self` with the given value of `y`.
189 #[inline]
190 #[must_use]
191 pub fn with_y(mut self, y: f32) -> Self {
192 self.y = y;
193 self
194 }
195
196 /// Creates a 3D vector from `self` with the given value of `z`.
197 #[inline]
198 #[must_use]
199 pub fn with_z(mut self, z: f32) -> Self {
200 self.z = z;
201 self
202 }
203
204 /// Computes the dot product of `self` and `rhs`.
205 #[inline]
206 #[must_use]
207 pub fn dot(self, rhs: Self) -> f32 {
208 unsafe { dot3(self.0, rhs.0) }
209 }
210
211 /// Returns a vector where every component is the dot product of `self` and `rhs`.
212 #[inline]
213 #[must_use]
214 pub fn dot_into_vec(self, rhs: Self) -> Self {
215 Self(unsafe { dot3_into_m128(self.0, rhs.0) })
216 }
217
218 /// Computes the cross product of `self` and `rhs`.
219 #[inline]
220 #[must_use]
221 pub fn cross(self, rhs: Self) -> Self {
222 unsafe {
223 // x <- a.y*b.z - a.z*b.y
224 // y <- a.z*b.x - a.x*b.z
225 // z <- a.x*b.y - a.y*b.x
226 // We can save a shuffle by grouping it in this wacky order:
227 // (self.zxy() * rhs - self * rhs.zxy()).zxy()
228 let lhszxy = _mm_shuffle_ps(self.0, self.0, 0b01_01_00_10);
229 let rhszxy = _mm_shuffle_ps(rhs.0, rhs.0, 0b01_01_00_10);
230 let lhszxy_rhs = _mm_mul_ps(lhszxy, rhs.0);
231 let rhszxy_lhs = _mm_mul_ps(rhszxy, self.0);
232 let sub = _mm_sub_ps(lhszxy_rhs, rhszxy_lhs);
233 Self(_mm_shuffle_ps(sub, sub, 0b01_01_00_10))
234 }
235 }
236
237 /// Returns a vector containing the minimum values for each element of `self` and `rhs`.
238 ///
239 /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`.
240 #[inline]
241 #[must_use]
242 pub fn min(self, rhs: Self) -> Self {
243 Self(unsafe { _mm_min_ps(self.0, rhs.0) })
244 }
245
246 /// Returns a vector containing the maximum values for each element of `self` and `rhs`.
247 ///
248 /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`.
249 #[inline]
250 #[must_use]
251 pub fn max(self, rhs: Self) -> Self {
252 Self(unsafe { _mm_max_ps(self.0, rhs.0) })
253 }
254
255 /// Component-wise clamping of values, similar to [`f32::clamp`].
256 ///
257 /// Each element in `min` must be less-or-equal to the corresponding element in `max`.
258 ///
259 /// # Panics
260 ///
261 /// Will panic if `min` is greater than `max` when `glam_assert` is enabled.
262 #[inline]
263 #[must_use]
264 pub fn clamp(self, min: Self, max: Self) -> Self {
265 glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
266 self.max(min).min(max)
267 }
268
269 /// Returns the horizontal minimum of `self`.
270 ///
271 /// In other words this computes `min(x, y, ..)`.
272 #[inline]
273 #[must_use]
274 pub fn min_element(self) -> f32 {
275 unsafe {
276 let v = self.0;
277 let v = _mm_min_ps(v, _mm_shuffle_ps(v, v, 0b01_01_10_10));
278 let v = _mm_min_ps(v, _mm_shuffle_ps(v, v, 0b00_00_00_01));
279 _mm_cvtss_f32(v)
280 }
281 }
282
283 /// Returns the horizontal maximum of `self`.
284 ///
285 /// In other words this computes `max(x, y, ..)`.
286 #[inline]
287 #[must_use]
288 pub fn max_element(self) -> f32 {
289 unsafe {
290 let v = self.0;
291 let v = _mm_max_ps(v, _mm_shuffle_ps(v, v, 0b00_00_10_10));
292 let v = _mm_max_ps(v, _mm_shuffle_ps(v, v, 0b00_00_00_01));
293 _mm_cvtss_f32(v)
294 }
295 }
296
297 /// Returns the sum of all elements of `self`.
298 ///
299 /// In other words, this computes `self.x + self.y + ..`.
300 #[inline]
301 #[must_use]
302 pub fn element_sum(self) -> f32 {
303 unsafe {
304 let v = self.0;
305 let v = _mm_add_ps(v, _mm_shuffle_ps(v, Self::ZERO.0, 0b00_11_00_01));
306 let v = _mm_add_ps(v, _mm_shuffle_ps(v, v, 0b00_00_00_10));
307 _mm_cvtss_f32(v)
308 }
309 }
310
311 /// Returns the product of all elements of `self`.
312 ///
313 /// In other words, this computes `self.x * self.y * ..`.
314 #[inline]
315 #[must_use]
316 pub fn element_product(self) -> f32 {
317 unsafe {
318 let v = self.0;
319 let v = _mm_mul_ps(v, _mm_shuffle_ps(v, Self::ONE.0, 0b00_11_00_01));
320 let v = _mm_mul_ps(v, _mm_shuffle_ps(v, v, 0b00_00_00_10));
321 _mm_cvtss_f32(v)
322 }
323 }
324
325 /// Returns a vector mask containing the result of a `==` comparison for each element of
326 /// `self` and `rhs`.
327 ///
328 /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all
329 /// elements.
330 #[inline]
331 #[must_use]
332 pub fn cmpeq(self, rhs: Self) -> BVec3A {
333 BVec3A(unsafe { _mm_cmpeq_ps(self.0, rhs.0) })
334 }
335
336 /// Returns a vector mask containing the result of a `!=` comparison for each element of
337 /// `self` and `rhs`.
338 ///
339 /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all
340 /// elements.
341 #[inline]
342 #[must_use]
343 pub fn cmpne(self, rhs: Self) -> BVec3A {
344 BVec3A(unsafe { _mm_cmpneq_ps(self.0, rhs.0) })
345 }
346
347 /// Returns a vector mask containing the result of a `>=` comparison for each element of
348 /// `self` and `rhs`.
349 ///
350 /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all
351 /// elements.
352 #[inline]
353 #[must_use]
354 pub fn cmpge(self, rhs: Self) -> BVec3A {
355 BVec3A(unsafe { _mm_cmpge_ps(self.0, rhs.0) })
356 }
357
358 /// Returns a vector mask containing the result of a `>` comparison for each element of
359 /// `self` and `rhs`.
360 ///
361 /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all
362 /// elements.
363 #[inline]
364 #[must_use]
365 pub fn cmpgt(self, rhs: Self) -> BVec3A {
366 BVec3A(unsafe { _mm_cmpgt_ps(self.0, rhs.0) })
367 }
368
369 /// Returns a vector mask containing the result of a `<=` comparison for each element of
370 /// `self` and `rhs`.
371 ///
372 /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all
373 /// elements.
374 #[inline]
375 #[must_use]
376 pub fn cmple(self, rhs: Self) -> BVec3A {
377 BVec3A(unsafe { _mm_cmple_ps(self.0, rhs.0) })
378 }
379
380 /// Returns a vector mask containing the result of a `<` comparison for each element of
381 /// `self` and `rhs`.
382 ///
383 /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all
384 /// elements.
385 #[inline]
386 #[must_use]
387 pub fn cmplt(self, rhs: Self) -> BVec3A {
388 BVec3A(unsafe { _mm_cmplt_ps(self.0, rhs.0) })
389 }
390
391 /// Returns a vector containing the absolute value of each element of `self`.
392 #[inline]
393 #[must_use]
394 pub fn abs(self) -> Self {
395 Self(unsafe { crate::sse2::m128_abs(self.0) })
396 }
397
398 /// Returns a vector with elements representing the sign of `self`.
399 ///
400 /// - `1.0` if the number is positive, `+0.0` or `INFINITY`
401 /// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY`
402 /// - `NAN` if the number is `NAN`
403 #[inline]
404 #[must_use]
405 pub fn signum(self) -> Self {
406 let result = Self(unsafe { _mm_or_ps(_mm_and_ps(self.0, Self::NEG_ONE.0), Self::ONE.0) });
407 let mask = self.is_nan_mask();
408 Self::select(mask, self, result)
409 }
410
411 /// Returns a vector with signs of `rhs` and the magnitudes of `self`.
412 #[inline]
413 #[must_use]
414 pub fn copysign(self, rhs: Self) -> Self {
415 let mask = Self::splat(-0.0);
416 Self(unsafe { _mm_or_ps(_mm_and_ps(rhs.0, mask.0), _mm_andnot_ps(mask.0, self.0)) })
417 }
418
419 /// Returns a bitmask with the lowest 3 bits set to the sign bits from the elements of `self`.
420 ///
421 /// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes
422 /// into the first lowest bit, element `y` into the second, etc.
423 #[inline]
424 #[must_use]
425 pub fn is_negative_bitmask(self) -> u32 {
426 unsafe { (_mm_movemask_ps(self.0) as u32) & 0x7 }
427 }
428
429 /// Returns `true` if, and only if, all elements are finite. If any element is either
430 /// `NaN`, positive or negative infinity, this will return `false`.
431 #[inline]
432 #[must_use]
433 pub fn is_finite(self) -> bool {
434 self.x.is_finite() && self.y.is_finite() && self.z.is_finite()
435 }
436
437 /// Returns `true` if any elements are `NaN`.
438 #[inline]
439 #[must_use]
440 pub fn is_nan(self) -> bool {
441 self.is_nan_mask().any()
442 }
443
444 /// Performs `is_nan` on each element of self, returning a vector mask of the results.
445 ///
446 /// In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`.
447 #[inline]
448 #[must_use]
449 pub fn is_nan_mask(self) -> BVec3A {
450 BVec3A(unsafe { _mm_cmpunord_ps(self.0, self.0) })
451 }
452
453 /// Computes the length of `self`.
454 #[doc(alias = "magnitude")]
455 #[inline]
456 #[must_use]
457 pub fn length(self) -> f32 {
458 unsafe {
459 let dot = dot3_in_x(self.0, self.0);
460 _mm_cvtss_f32(_mm_sqrt_ps(dot))
461 }
462 }
463
464 /// Computes the squared length of `self`.
465 ///
466 /// This is faster than `length()` as it avoids a square root operation.
467 #[doc(alias = "magnitude2")]
468 #[inline]
469 #[must_use]
470 pub fn length_squared(self) -> f32 {
471 self.dot(self)
472 }
473
474 /// Computes `1.0 / length()`.
475 ///
476 /// For valid results, `self` must _not_ be of length zero.
477 #[inline]
478 #[must_use]
479 pub fn length_recip(self) -> f32 {
480 unsafe {
481 let dot = dot3_in_x(self.0, self.0);
482 _mm_cvtss_f32(_mm_div_ps(Self::ONE.0, _mm_sqrt_ps(dot)))
483 }
484 }
485
486 /// Computes the Euclidean distance between two points in space.
487 #[inline]
488 #[must_use]
489 pub fn distance(self, rhs: Self) -> f32 {
490 (self - rhs).length()
491 }
492
493 /// Compute the squared euclidean distance between two points in space.
494 #[inline]
495 #[must_use]
496 pub fn distance_squared(self, rhs: Self) -> f32 {
497 (self - rhs).length_squared()
498 }
499
500 /// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`.
501 #[inline]
502 #[must_use]
503 pub fn div_euclid(self, rhs: Self) -> Self {
504 Self::new(
505 math::div_euclid(self.x, rhs.x),
506 math::div_euclid(self.y, rhs.y),
507 math::div_euclid(self.z, rhs.z),
508 )
509 }
510
511 /// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`.
512 ///
513 /// [Euclidean division]: f32::rem_euclid
514 #[inline]
515 #[must_use]
516 pub fn rem_euclid(self, rhs: Self) -> Self {
517 Self::new(
518 math::rem_euclid(self.x, rhs.x),
519 math::rem_euclid(self.y, rhs.y),
520 math::rem_euclid(self.z, rhs.z),
521 )
522 }
523
524 /// Returns `self` normalized to length 1.0.
525 ///
526 /// For valid results, `self` must _not_ be of length zero, nor very close to zero.
527 ///
528 /// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`].
529 ///
530 /// Panics
531 ///
532 /// Will panic if `self` is zero length when `glam_assert` is enabled.
533 #[inline]
534 #[must_use]
535 pub fn normalize(self) -> Self {
536 unsafe {
537 let length = _mm_sqrt_ps(dot3_into_m128(self.0, self.0));
538 #[allow(clippy::let_and_return)]
539 let normalized = Self(_mm_div_ps(self.0, length));
540 glam_assert!(normalized.is_finite());
541 normalized
542 }
543 }
544
545 /// Returns `self` normalized to length 1.0 if possible, else returns `None`.
546 ///
547 /// In particular, if the input is zero (or very close to zero), or non-finite,
548 /// the result of this operation will be `None`.
549 ///
550 /// See also [`Self::normalize_or_zero()`].
551 #[inline]
552 #[must_use]
553 pub fn try_normalize(self) -> Option<Self> {
554 let rcp = self.length_recip();
555 if rcp.is_finite() && rcp > 0.0 {
556 Some(self * rcp)
557 } else {
558 None
559 }
560 }
561
562 /// Returns `self` normalized to length 1.0 if possible, else returns a
563 /// fallback value.
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 the fallback value.
567 ///
568 /// See also [`Self::try_normalize()`].
569 #[inline]
570 #[must_use]
571 pub fn normalize_or(self, fallback: Self) -> Self {
572 let rcp = self.length_recip();
573 if rcp.is_finite() && rcp > 0.0 {
574 self * rcp
575 } else {
576 fallback
577 }
578 }
579
580 /// Returns `self` normalized to length 1.0 if possible, else returns zero.
581 ///
582 /// In particular, if the input is zero (or very close to zero), or non-finite,
583 /// the result of this operation will be zero.
584 ///
585 /// See also [`Self::try_normalize()`].
586 #[inline]
587 #[must_use]
588 pub fn normalize_or_zero(self) -> Self {
589 self.normalize_or(Self::ZERO)
590 }
591
592 /// Returns whether `self` is length `1.0` or not.
593 ///
594 /// Uses a precision threshold of approximately `1e-4`.
595 #[inline]
596 #[must_use]
597 pub fn is_normalized(self) -> bool {
598 math::abs(self.length_squared() - 1.0) <= 2e-4
599 }
600
601 /// Returns the vector projection of `self` onto `rhs`.
602 ///
603 /// `rhs` must be of non-zero length.
604 ///
605 /// # Panics
606 ///
607 /// Will panic if `rhs` is zero length when `glam_assert` is enabled.
608 #[inline]
609 #[must_use]
610 pub fn project_onto(self, rhs: Self) -> Self {
611 let other_len_sq_rcp = rhs.dot(rhs).recip();
612 glam_assert!(other_len_sq_rcp.is_finite());
613 rhs * self.dot(rhs) * other_len_sq_rcp
614 }
615
616 /// Returns the vector rejection of `self` from `rhs`.
617 ///
618 /// The vector rejection is the vector perpendicular to the projection of `self` onto
619 /// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`.
620 ///
621 /// `rhs` must be of non-zero length.
622 ///
623 /// # Panics
624 ///
625 /// Will panic if `rhs` has a length of zero when `glam_assert` is enabled.
626 #[inline]
627 #[must_use]
628 pub fn reject_from(self, rhs: Self) -> Self {
629 self - self.project_onto(rhs)
630 }
631
632 /// Returns the vector projection of `self` onto `rhs`.
633 ///
634 /// `rhs` must be normalized.
635 ///
636 /// # Panics
637 ///
638 /// Will panic if `rhs` is not normalized when `glam_assert` is enabled.
639 #[inline]
640 #[must_use]
641 pub fn project_onto_normalized(self, rhs: Self) -> Self {
642 glam_assert!(rhs.is_normalized());
643 rhs * self.dot(rhs)
644 }
645
646 /// Returns the vector rejection of `self` from `rhs`.
647 ///
648 /// The vector rejection is the vector perpendicular to the projection of `self` onto
649 /// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`.
650 ///
651 /// `rhs` must be normalized.
652 ///
653 /// # Panics
654 ///
655 /// Will panic if `rhs` is not normalized when `glam_assert` is enabled.
656 #[inline]
657 #[must_use]
658 pub fn reject_from_normalized(self, rhs: Self) -> Self {
659 self - self.project_onto_normalized(rhs)
660 }
661
662 /// Returns a vector containing the nearest integer to a number for each element of `self`.
663 /// Round half-way cases away from 0.0.
664 #[inline]
665 #[must_use]
666 pub fn round(self) -> Self {
667 Self(unsafe { m128_round(self.0) })
668 }
669
670 /// Returns a vector containing the largest integer less than or equal to a number for each
671 /// element of `self`.
672 #[inline]
673 #[must_use]
674 pub fn floor(self) -> Self {
675 Self(unsafe { m128_floor(self.0) })
676 }
677
678 /// Returns a vector containing the smallest integer greater than or equal to a number for
679 /// each element of `self`.
680 #[inline]
681 #[must_use]
682 pub fn ceil(self) -> Self {
683 Self(unsafe { m128_ceil(self.0) })
684 }
685
686 /// Returns a vector containing the integer part each element of `self`. This means numbers are
687 /// always truncated towards zero.
688 #[inline]
689 #[must_use]
690 pub fn trunc(self) -> Self {
691 Self(unsafe { m128_trunc(self.0) })
692 }
693
694 /// Returns a vector containing the fractional part of the vector as `self - self.trunc()`.
695 ///
696 /// Note that this differs from the GLSL implementation of `fract` which returns
697 /// `self - self.floor()`.
698 ///
699 /// Note that this is fast but not precise for large numbers.
700 #[inline]
701 #[must_use]
702 pub fn fract(self) -> Self {
703 self - self.trunc()
704 }
705
706 /// Returns a vector containing the fractional part of the vector as `self - self.floor()`.
707 ///
708 /// Note that this differs from the Rust implementation of `fract` which returns
709 /// `self - self.trunc()`.
710 ///
711 /// Note that this is fast but not precise for large numbers.
712 #[inline]
713 #[must_use]
714 pub fn fract_gl(self) -> Self {
715 self - self.floor()
716 }
717
718 /// Returns a vector containing `e^self` (the exponential function) for each element of
719 /// `self`.
720 #[inline]
721 #[must_use]
722 pub fn exp(self) -> Self {
723 Self::new(math::exp(self.x), math::exp(self.y), math::exp(self.z))
724 }
725
726 /// Returns a vector containing each element of `self` raised to the power of `n`.
727 #[inline]
728 #[must_use]
729 pub fn powf(self, n: f32) -> Self {
730 Self::new(
731 math::powf(self.x, n),
732 math::powf(self.y, n),
733 math::powf(self.z, n),
734 )
735 }
736
737 /// Returns a vector containing the reciprocal `1.0/n` of each element of `self`.
738 #[inline]
739 #[must_use]
740 pub fn recip(self) -> Self {
741 Self(unsafe { _mm_div_ps(Self::ONE.0, self.0) })
742 }
743
744 /// Performs a linear interpolation between `self` and `rhs` based on the value `s`.
745 ///
746 /// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result
747 /// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly
748 /// extrapolated.
749 #[doc(alias = "mix")]
750 #[inline]
751 #[must_use]
752 pub fn lerp(self, rhs: Self, s: f32) -> Self {
753 self + ((rhs - self) * s)
754 }
755
756 /// Moves towards `rhs` based on the value `d`.
757 ///
758 /// When `d` is `0.0`, the result will be equal to `self`. When `d` is equal to
759 /// `self.distance(rhs)`, the result will be equal to `rhs`. Will not go past `rhs`.
760 #[inline]
761 #[must_use]
762 pub fn move_towards(&self, rhs: Self, d: f32) -> Self {
763 let a = rhs - *self;
764 let len = a.length();
765 if len <= d || len <= 1e-4 {
766 return rhs;
767 }
768 *self + a / len * d
769 }
770
771 /// Calculates the midpoint between `self` and `rhs`.
772 ///
773 /// The midpoint is the average of, or halfway point between, two vectors.
774 /// `a.midpoint(b)` should yield the same result as `a.lerp(b, 0.5)`
775 /// while being slightly cheaper to compute.
776 #[inline]
777 pub fn midpoint(self, rhs: Self) -> Self {
778 (self + rhs) * 0.5
779 }
780
781 /// Returns true if the absolute difference of all elements between `self` and `rhs` is
782 /// less than or equal to `max_abs_diff`.
783 ///
784 /// This can be used to compare if two vectors contain similar elements. It works best when
785 /// comparing with a known value. The `max_abs_diff` that should be used used depends on
786 /// the values being compared against.
787 ///
788 /// For more see
789 /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/).
790 #[inline]
791 #[must_use]
792 pub fn abs_diff_eq(self, rhs: Self, max_abs_diff: f32) -> bool {
793 self.sub(rhs).abs().cmple(Self::splat(max_abs_diff)).all()
794 }
795
796 /// Returns a vector with a length no less than `min` and no more than `max`.
797 ///
798 /// # Panics
799 ///
800 /// Will panic if `min` is greater than `max`, or if either `min` or `max` is negative, when `glam_assert` is enabled.
801 #[inline]
802 #[must_use]
803 pub fn clamp_length(self, min: f32, max: f32) -> Self {
804 glam_assert!(0.0 <= min);
805 glam_assert!(min <= max);
806 let length_sq = self.length_squared();
807 if length_sq < min * min {
808 min * (self / math::sqrt(length_sq))
809 } else if length_sq > max * max {
810 max * (self / math::sqrt(length_sq))
811 } else {
812 self
813 }
814 }
815
816 /// Returns a vector with a length no more than `max`.
817 ///
818 /// # Panics
819 ///
820 /// Will panic if `max` is negative when `glam_assert` is enabled.
821 #[inline]
822 #[must_use]
823 pub fn clamp_length_max(self, max: f32) -> Self {
824 glam_assert!(0.0 <= max);
825 let length_sq = self.length_squared();
826 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 less than `min`.
834 ///
835 /// # Panics
836 ///
837 /// Will panic if `min` is negative when `glam_assert` is enabled.
838 #[inline]
839 #[must_use]
840 pub fn clamp_length_min(self, min: f32) -> Self {
841 glam_assert!(0.0 <= min);
842 let length_sq = self.length_squared();
843 if length_sq < min * min {
844 min * (self / math::sqrt(length_sq))
845 } else {
846 self
847 }
848 }
849
850 /// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding
851 /// error, yielding a more accurate result than an unfused multiply-add.
852 ///
853 /// Using `mul_add` *may* be more performant than an unfused multiply-add if the target
854 /// architecture has a dedicated fma CPU instruction. However, this is not always true,
855 /// and will be heavily dependant on designing algorithms with specific target hardware in
856 /// mind.
857 #[inline]
858 #[must_use]
859 pub fn mul_add(self, a: Self, b: Self) -> Self {
860 #[cfg(target_feature = "fma")]
861 unsafe {
862 Self(_mm_fmadd_ps(self.0, a.0, b.0))
863 }
864 #[cfg(not(target_feature = "fma"))]
865 Self::new(
866 math::mul_add(self.x, a.x, b.x),
867 math::mul_add(self.y, a.y, b.y),
868 math::mul_add(self.z, a.z, b.z),
869 )
870 }
871
872 /// Returns the angle (in radians) between two vectors in the range `[0, +π]`.
873 ///
874 /// The inputs do not need to be unit vectors however they must be non-zero.
875 #[inline]
876 #[must_use]
877 pub fn angle_between(self, rhs: Self) -> f32 {
878 math::acos_approx(
879 self.dot(rhs)
880 .div(math::sqrt(self.length_squared().mul(rhs.length_squared()))),
881 )
882 }
883
884 /// Returns some vector that is orthogonal to the given one.
885 ///
886 /// The input vector must be finite and non-zero.
887 ///
888 /// The output vector is not necessarily unit length. For that use
889 /// [`Self::any_orthonormal_vector()`] instead.
890 #[inline]
891 #[must_use]
892 pub fn any_orthogonal_vector(&self) -> Self {
893 // This can probably be optimized
894 if math::abs(self.x) > math::abs(self.y) {
895 Self::new(-self.z, 0.0, self.x) // self.cross(Self::Y)
896 } else {
897 Self::new(0.0, self.z, -self.y) // self.cross(Self::X)
898 }
899 }
900
901 /// Returns any unit vector that is orthogonal to the given one.
902 ///
903 /// The input vector must be unit length.
904 ///
905 /// # Panics
906 ///
907 /// Will panic if `self` is not normalized when `glam_assert` is enabled.
908 #[inline]
909 #[must_use]
910 pub fn any_orthonormal_vector(&self) -> Self {
911 glam_assert!(self.is_normalized());
912 // From https://graphics.pixar.com/library/OrthonormalB/paper.pdf
913 let sign = math::signum(self.z);
914 let a = -1.0 / (sign + self.z);
915 let b = self.x * self.y * a;
916 Self::new(b, sign + self.y * self.y * a, -self.y)
917 }
918
919 /// Given a unit vector return two other vectors that together form an orthonormal
920 /// basis. That is, all three vectors are orthogonal to each other and are normalized.
921 ///
922 /// # Panics
923 ///
924 /// Will panic if `self` is not normalized when `glam_assert` is enabled.
925 #[inline]
926 #[must_use]
927 pub fn any_orthonormal_pair(&self) -> (Self, Self) {
928 glam_assert!(self.is_normalized());
929 // From https://graphics.pixar.com/library/OrthonormalB/paper.pdf
930 let sign = math::signum(self.z);
931 let a = -1.0 / (sign + self.z);
932 let b = self.x * self.y * a;
933 (
934 Self::new(1.0 + sign * self.x * self.x * a, sign * b, -sign * self.x),
935 Self::new(b, sign + self.y * self.y * a, -self.y),
936 )
937 }
938
939 /// Casts all elements of `self` to `f64`.
940 #[inline]
941 #[must_use]
942 pub fn as_dvec3(&self) -> crate::DVec3 {
943 crate::DVec3::new(self.x as f64, self.y as f64, self.z as f64)
944 }
945
946 /// Casts all elements of `self` to `i16`.
947 #[inline]
948 #[must_use]
949 pub fn as_i16vec3(&self) -> crate::I16Vec3 {
950 crate::I16Vec3::new(self.x as i16, self.y as i16, self.z as i16)
951 }
952
953 /// Casts all elements of `self` to `u16`.
954 #[inline]
955 #[must_use]
956 pub fn as_u16vec3(&self) -> crate::U16Vec3 {
957 crate::U16Vec3::new(self.x as u16, self.y as u16, self.z as u16)
958 }
959
960 /// Casts all elements of `self` to `i32`.
961 #[inline]
962 #[must_use]
963 pub fn as_ivec3(&self) -> crate::IVec3 {
964 crate::IVec3::new(self.x as i32, self.y as i32, self.z as i32)
965 }
966
967 /// Casts all elements of `self` to `u32`.
968 #[inline]
969 #[must_use]
970 pub fn as_uvec3(&self) -> crate::UVec3 {
971 crate::UVec3::new(self.x as u32, self.y as u32, self.z as u32)
972 }
973
974 /// Casts all elements of `self` to `i64`.
975 #[inline]
976 #[must_use]
977 pub fn as_i64vec3(&self) -> crate::I64Vec3 {
978 crate::I64Vec3::new(self.x as i64, self.y as i64, self.z as i64)
979 }
980
981 /// Casts all elements of `self` to `u64`.
982 #[inline]
983 #[must_use]
984 pub fn as_u64vec3(&self) -> crate::U64Vec3 {
985 crate::U64Vec3::new(self.x as u64, self.y as u64, self.z as u64)
986 }
987 }
988
989 impl Default for Vec3A {
990 #[inline(always)]
991 fn default() -> Self {
992 Self::ZERO
993 }
994 }
995
996 impl PartialEq for Vec3A {
997 #[inline]
998 fn eq(&self, rhs: &Self) -> bool {
999 self.cmpeq(*rhs).all()
1000 }
1001 }
1002
1003 impl Div<Vec3A> for Vec3A {
1004 type Output = Self;
1005 #[inline]
1006 fn div(self, rhs: Self) -> Self {
1007 Self(unsafe { _mm_div_ps(self.0, rhs.0) })
1008 }
1009 }
1010
1011 impl DivAssign<Vec3A> for Vec3A {
1012 #[inline]
1013 fn div_assign(&mut self, rhs: Self) {
1014 self.0 = unsafe { _mm_div_ps(self.0, rhs.0) };
1015 }
1016 }
1017
1018 impl Div<f32> for Vec3A {
1019 type Output = Self;
1020 #[inline]
1021 fn div(self, rhs: f32) -> Self {
1022 Self(unsafe { _mm_div_ps(self.0, _mm_set1_ps(rhs)) })
1023 }
1024 }
1025
1026 impl DivAssign<f32> for Vec3A {
1027 #[inline]
1028 fn div_assign(&mut self, rhs: f32) {
1029 self.0 = unsafe { _mm_div_ps(self.0, _mm_set1_ps(rhs)) };
1030 }
1031 }
1032
1033 impl Div<Vec3A> for f32 {
1034 type Output = Vec3A;
1035 #[inline]
1036 fn div(self, rhs: Vec3A) -> Vec3A {
1037 Vec3A(unsafe { _mm_div_ps(_mm_set1_ps(self), rhs.0) })
1038 }
1039 }
1040
1041 impl Mul<Vec3A> for Vec3A {
1042 type Output = Self;
1043 #[inline]
1044 fn mul(self, rhs: Self) -> Self {
1045 Self(unsafe { _mm_mul_ps(self.0, rhs.0) })
1046 }
1047 }
1048
1049 impl MulAssign<Vec3A> for Vec3A {
1050 #[inline]
1051 fn mul_assign(&mut self, rhs: Self) {
1052 self.0 = unsafe { _mm_mul_ps(self.0, rhs.0) };
1053 }
1054 }
1055
1056 impl Mul<f32> for Vec3A {
1057 type Output = Self;
1058 #[inline]
1059 fn mul(self, rhs: f32) -> Self {
1060 Self(unsafe { _mm_mul_ps(self.0, _mm_set1_ps(rhs)) })
1061 }
1062 }
1063
1064 impl MulAssign<f32> for Vec3A {
1065 #[inline]
1066 fn mul_assign(&mut self, rhs: f32) {
1067 self.0 = unsafe { _mm_mul_ps(self.0, _mm_set1_ps(rhs)) };
1068 }
1069 }
1070
1071 impl Mul<Vec3A> for f32 {
1072 type Output = Vec3A;
1073 #[inline]
1074 fn mul(self, rhs: Vec3A) -> Vec3A {
1075 Vec3A(unsafe { _mm_mul_ps(_mm_set1_ps(self), rhs.0) })
1076 }
1077 }
1078
1079 impl Add<Vec3A> for Vec3A {
1080 type Output = Self;
1081 #[inline]
1082 fn add(self, rhs: Self) -> Self {
1083 Self(unsafe { _mm_add_ps(self.0, rhs.0) })
1084 }
1085 }
1086
1087 impl AddAssign<Vec3A> for Vec3A {
1088 #[inline]
1089 fn add_assign(&mut self, rhs: Self) {
1090 self.0 = unsafe { _mm_add_ps(self.0, rhs.0) };
1091 }
1092 }
1093
1094 impl Add<f32> for Vec3A {
1095 type Output = Self;
1096 #[inline]
1097 fn add(self, rhs: f32) -> Self {
1098 Self(unsafe { _mm_add_ps(self.0, _mm_set1_ps(rhs)) })
1099 }
1100 }
1101
1102 impl AddAssign<f32> for Vec3A {
1103 #[inline]
1104 fn add_assign(&mut self, rhs: f32) {
1105 self.0 = unsafe { _mm_add_ps(self.0, _mm_set1_ps(rhs)) };
1106 }
1107 }
1108
1109 impl Add<Vec3A> for f32 {
1110 type Output = Vec3A;
1111 #[inline]
1112 fn add(self, rhs: Vec3A) -> Vec3A {
1113 Vec3A(unsafe { _mm_add_ps(_mm_set1_ps(self), rhs.0) })
1114 }
1115 }
1116
1117 impl Sub<Vec3A> for Vec3A {
1118 type Output = Self;
1119 #[inline]
1120 fn sub(self, rhs: Self) -> Self {
1121 Self(unsafe { _mm_sub_ps(self.0, rhs.0) })
1122 }
1123 }
1124
1125 impl SubAssign<Vec3A> for Vec3A {
1126 #[inline]
1127 fn sub_assign(&mut self, rhs: Vec3A) {
1128 self.0 = unsafe { _mm_sub_ps(self.0, rhs.0) };
1129 }
1130 }
1131
1132 impl Sub<f32> for Vec3A {
1133 type Output = Self;
1134 #[inline]
1135 fn sub(self, rhs: f32) -> Self {
1136 Self(unsafe { _mm_sub_ps(self.0, _mm_set1_ps(rhs)) })
1137 }
1138 }
1139
1140 impl SubAssign<f32> for Vec3A {
1141 #[inline]
1142 fn sub_assign(&mut self, rhs: f32) {
1143 self.0 = unsafe { _mm_sub_ps(self.0, _mm_set1_ps(rhs)) };
1144 }
1145 }
1146
1147 impl Sub<Vec3A> for f32 {
1148 type Output = Vec3A;
1149 #[inline]
1150 fn sub(self, rhs: Vec3A) -> Vec3A {
1151 Vec3A(unsafe { _mm_sub_ps(_mm_set1_ps(self), rhs.0) })
1152 }
1153 }
1154
1155 impl Rem<Vec3A> for Vec3A {
1156 type Output = Self;
1157 #[inline]
1158 fn rem(self, rhs: Self) -> Self {
1159 unsafe {
1160 let n = m128_floor(_mm_div_ps(self.0, rhs.0));
1161 Self(_mm_sub_ps(self.0, _mm_mul_ps(n, rhs.0)))
1162 }
1163 }
1164 }
1165
1166 impl RemAssign<Vec3A> for Vec3A {
1167 #[inline]
1168 fn rem_assign(&mut self, rhs: Self) {
1169 *self = self.rem(rhs);
1170 }
1171 }
1172
1173 impl Rem<f32> for Vec3A {
1174 type Output = Self;
1175 #[inline]
1176 fn rem(self, rhs: f32) -> Self {
1177 self.rem(Self::splat(rhs))
1178 }
1179 }
1180
1181 impl RemAssign<f32> for Vec3A {
1182 #[inline]
1183 fn rem_assign(&mut self, rhs: f32) {
1184 *self = self.rem(Self::splat(rhs));
1185 }
1186 }
1187
1188 impl Rem<Vec3A> for f32 {
1189 type Output = Vec3A;
1190 #[inline]
1191 fn rem(self, rhs: Vec3A) -> Vec3A {
1192 Vec3A::splat(self).rem(rhs)
1193 }
1194 }
1195
1196 #[cfg(not(target_arch = "spirv"))]
1197 impl AsRef<[f32; 3]> for Vec3A {
1198 #[inline]
1199 fn as_ref(&self) -> &[f32; 3] {
1200 unsafe { &*(self as *const Vec3A as *const [f32; 3]) }
1201 }
1202 }
1203
1204 #[cfg(not(target_arch = "spirv"))]
1205 impl AsMut<[f32; 3]> for Vec3A {
1206 #[inline]
1207 fn as_mut(&mut self) -> &mut [f32; 3] {
1208 unsafe { &mut *(self as *mut Vec3A as *mut [f32; 3]) }
1209 }
1210 }
1211
1212 impl Sum for Vec3A {
1213 #[inline]
1214 fn sum<I>(iter: I) -> Self
1215 where
1216 I: Iterator<Item = Self>,
1217 {
1218 iter.fold(Self::ZERO, Self::add)
1219 }
1220 }
1221
1222 impl<'a> Sum<&'a Self> for Vec3A {
1223 #[inline]
1224 fn sum<I>(iter: I) -> Self
1225 where
1226 I: Iterator<Item = &'a Self>,
1227 {
1228 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
1229 }
1230 }
1231
1232 impl Product for Vec3A {
1233 #[inline]
1234 fn product<I>(iter: I) -> Self
1235 where
1236 I: Iterator<Item = Self>,
1237 {
1238 iter.fold(Self::ONE, Self::mul)
1239 }
1240 }
1241
1242 impl<'a> Product<&'a Self> for Vec3A {
1243 #[inline]
1244 fn product<I>(iter: I) -> Self
1245 where
1246 I: Iterator<Item = &'a Self>,
1247 {
1248 iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
1249 }
1250 }
1251
1252 impl Neg for Vec3A {
1253 type Output = Self;
1254 #[inline]
1255 fn neg(self) -> Self {
1256 Self(unsafe { _mm_xor_ps(_mm_set1_ps(-0.0), self.0) })
1257 }
1258 }
1259
1260 impl Index<usize> for Vec3A {
1261 type Output = f32;
1262 #[inline]
1263 fn index(&self, index: usize) -> &Self::Output {
1264 match index {
1265 0 => &self.x,
1266 1 => &self.y,
1267 2 => &self.z,
1268 _ => panic!("index out of bounds"),
1269 }
1270 }
1271 }
1272
1273 impl IndexMut<usize> for Vec3A {
1274 #[inline]
1275 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1276 match index {
1277 0 => &mut self.x,
1278 1 => &mut self.y,
1279 2 => &mut self.z,
1280 _ => panic!("index out of bounds"),
1281 }
1282 }
1283 }
1284
1285 #[cfg(not(target_arch = "spirv"))]
1286 impl fmt::Display for Vec3A {
1287 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1288 if let Some(p) = f.precision() {
1289 write!(f, "[{:.*}, {:.*}, {:.*}]", p, self.x, p, self.y, p, self.z)
1290 } else {
1291 write!(f, "[{}, {}, {}]", self.x, self.y, self.z)
1292 }
1293 }
1294 }
1295
1296 #[cfg(not(target_arch = "spirv"))]
1297 impl fmt::Debug for Vec3A {
1298 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1299 fmt.debug_tuple(stringify!(Vec3A))
1300 .field(&self.x)
1301 .field(&self.y)
1302 .field(&self.z)
1303 .finish()
1304 }
1305 }
1306
1307 impl From<Vec3A> for __m128 {
1308 #[inline(always)]
1309 fn from(t: Vec3A) -> Self {
1310 t.0
1311 }
1312 }
1313
1314 impl From<__m128> for Vec3A {
1315 #[inline(always)]
1316 fn from(t: __m128) -> Self {
1317 Self(t)
1318 }
1319 }
1320
1321 impl From<[f32; 3]> for Vec3A {
1322 #[inline]
1323 fn from(a: [f32; 3]) -> Self {
1324 Self::new(a[0], a[1], a[2])
1325 }
1326 }
1327
1328 impl From<Vec3A> for [f32; 3] {
1329 #[inline]
1330 fn from(v: Vec3A) -> Self {
1331 use crate::Align16;
1332 use core::mem::MaybeUninit;
1333 let mut out: MaybeUninit<Align16<Self>> = MaybeUninit::uninit();
1334 unsafe {
1335 _mm_store_ps(out.as_mut_ptr().cast(), v.0);
1336 out.assume_init().0
1337 }
1338 }
1339 }
1340
1341 impl From<(f32, f32, f32)> for Vec3A {
1342 #[inline]
1343 fn from(t: (f32, f32, f32)) -> Self {
1344 Self::new(t.0, t.1, t.2)
1345 }
1346 }
1347
1348 impl From<Vec3A> for (f32, f32, f32) {
1349 #[inline]
1350 fn from(v: Vec3A) -> Self {
1351 use crate::Align16;
1352 use core::mem::MaybeUninit;
1353 let mut out: MaybeUninit<Align16<Self>> = MaybeUninit::uninit();
1354 unsafe {
1355 _mm_store_ps(out.as_mut_ptr().cast(), v.0);
1356 out.assume_init().0
1357 }
1358 }
1359 }
1360
1361 impl From<Vec3> for Vec3A {
1362 #[inline]
1363 fn from(v: Vec3) -> Self {
1364 Self::new(v.x, v.y, v.z)
1365 }
1366 }
1367
1368 impl From<Vec3A> for Vec3 {
1369 #[inline]
1370 fn from(v: Vec3A) -> Self {
1371 use crate::Align16;
1372 use core::mem::MaybeUninit;
1373 let mut out: MaybeUninit<Align16<Self>> = MaybeUninit::uninit();
1374 unsafe {
1375 _mm_store_ps(out.as_mut_ptr().cast(), v.0);
1376 out.assume_init().0
1377 }
1378 }
1379 }
1380
1381 impl From<(Vec2, f32)> for Vec3A {
1382 #[inline]
1383 fn from((v, z): (Vec2, f32)) -> Self {
1384 Self::new(v.x, v.y, z)
1385 }
1386 }
1387
1388 impl Deref for Vec3A {
1389 type Target = crate::deref::Vec3<f32>;
1390 #[inline]
1391 fn deref(&self) -> &Self::Target {
1392 unsafe { &*(self as *const Self).cast() }
1393 }
1394 }
1395
1396 impl DerefMut for Vec3A {
1397 #[inline]
1398 fn deref_mut(&mut self) -> &mut Self::Target {
1399 unsafe { &mut *(self as *mut Self).cast() }
1400 }
1401 }
1402
1403 impl From<BVec3> for Vec3A {
1404 #[inline]
1405 fn from(v: BVec3) -> Self {
1406 Self::new(f32::from(v.x), f32::from(v.y), f32::from(v.z))
1407 }
1408 }
1409
1410 impl From<BVec3A> for Vec3A {
1411 #[inline]
1412 fn from(v: BVec3A) -> Self {
1413 let bool_array: [bool; 3] = v.into();
1414 Self::new(
1415 f32::from(bool_array[0]),
1416 f32::from(bool_array[1]),
1417 f32::from(bool_array[2]),
1418 )
1419 }
1420 }