Debian Codegraph @

debian/missing-sources/glam/src/f32/neon/vec3a.rs

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