Debian Codegraph @

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