Debian Codegraph @

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

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