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 /// Creates a 3-dimensional vector.
10 #[inline(always)]
11 #[must_use]
vec3a(x: f32, y: f32, z: f32) -> Vec3A12 pub const fn vec3a(x: f32, y: f32, z: f32) -> Vec3A {
13 Vec3A::new(x, y, z)
14 }
15
16 /// A 3-dimensional vector.
17 ///
18 /// SIMD vector types are used for storage on supported platforms for better
19 /// performance than the [`Vec3`] type.
20 ///
21 /// It is possible to convert between [`Vec3`] and [`Vec3A`] types using [`From`]
22 /// or [`Into`] trait implementations.
23 ///
24 /// This type is 16 byte aligned.
25 #[derive(Clone, Copy, PartialEq)]
26 #[cfg_attr(not(target_arch = "spirv"), repr(align(16)))]
27 #[cfg_attr(not(target_arch = "spirv"), repr(C))]
28 #[cfg_attr(target_arch = "spirv", repr(simd))]
29 pub struct Vec3A {
30 pub x: f32,
31 pub y: f32,
32 pub z: f32,
33 }
34
35 impl Vec3A {
36 /// All zeroes.
37 pub const ZERO: Self = Self::splat(0.0);
38
39 /// All ones.
40 pub const ONE: Self = Self::splat(1.0);
41
42 /// All negative ones.
43 pub const NEG_ONE: Self = Self::splat(-1.0);
44
45 /// All `f32::MIN`.
46 pub const MIN: Self = Self::splat(f32::MIN);
47
48 /// All `f32::MAX`.
49 pub const MAX: Self = Self::splat(f32::MAX);
50
51 /// All `f32::NAN`.
52 pub const NAN: Self = Self::splat(f32::NAN);
53
54 /// All `f32::INFINITY`.
55 pub const INFINITY: Self = Self::splat(f32::INFINITY);
56
57 /// All `f32::NEG_INFINITY`.
58 pub const NEG_INFINITY: Self = Self::splat(f32::NEG_INFINITY);
59
60 /// A unit vector pointing along the positive X axis.
61 pub const X: Self = Self::new(1.0, 0.0, 0.0);
62
63 /// A unit vector pointing along the positive Y axis.
64 pub const Y: Self = Self::new(0.0, 1.0, 0.0);
65
66 /// A unit vector pointing along the positive Z axis.
67 pub const Z: Self = Self::new(0.0, 0.0, 1.0);
68
69 /// A unit vector pointing along the negative X axis.
70 pub const NEG_X: Self = Self::new(-1.0, 0.0, 0.0);
71
72 /// A unit vector pointing along the negative Y axis.
73 pub const NEG_Y: Self = Self::new(0.0, -1.0, 0.0);
74
75 /// A unit vector pointing along the negative Z axis.
76 pub const NEG_Z: Self = Self::new(0.0, 0.0, -1.0);
77
78 /// The unit axes.
79 pub const AXES: [Self; 3] = [Self::X, Self::Y, Self::Z];
80
81 /// Creates a new vector.
82 #[inline(always)]
83 #[must_use]
new(x: f32, y: f32, z: f32) -> Self84 pub const fn new(x: f32, y: f32, z: f32) -> Self {
85 Self { x, y, z }
86 }
87
88 /// Creates a vector with all elements set to `v`.
89 #[inline]
90 #[must_use]
splat(v: f32) -> Self91 pub const fn splat(v: f32) -> Self {
92 Self { x: v, y: v, z: v }
93 }
94
95 /// Returns a vector containing each element of `self` modified by a mapping function `f`.
96 #[inline]
97 #[must_use]
map<F>(self, f: F) -> Self where F: Fn(f32) -> f32,98 pub fn map<F>(self, f: F) -> Self
99 where
100 F: Fn(f32) -> f32,
101 {
102 Self::new(f(self.x), f(self.y), f(self.z))
103 }
104
105 /// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use
106 /// for each element of `self`.
107 ///
108 /// A true element in the mask uses the corresponding element from `if_true`, and false
109 /// uses the element from `if_false`.
110 #[inline]
111 #[must_use]
select(mask: BVec3A, if_true: Self, if_false: Self) -> Self112 pub fn select(mask: BVec3A, if_true: Self, if_false: Self) -> Self {
113 Self {
114 x: if mask.test(0) { if_true.x } else { if_false.x },
115 y: if mask.test(1) { if_true.y } else { if_false.y },
116 z: if mask.test(2) { if_true.z } else { if_false.z },
117 }
118 }
119
120 /// Creates a new vector from an array.
121 #[inline]
122 #[must_use]
from_array(a: [f32; 3]) -> Self123 pub const fn from_array(a: [f32; 3]) -> Self {
124 Self::new(a[0], a[1], a[2])
125 }
126
127 /// `[x, y, z]`
128 #[inline]
129 #[must_use]
to_array(&self) -> [f32; 3]130 pub const fn to_array(&self) -> [f32; 3] {
131 [self.x, self.y, self.z]
132 }
133
134 /// Creates a vector from the first 3 values in `slice`.
135 ///
136 /// # Panics
137 ///
138 /// Panics if `slice` is less than 3 elements long.
139 #[inline]
140 #[must_use]
from_slice(slice: &[f32]) -> Self141 pub const fn from_slice(slice: &[f32]) -> Self {
142 assert!(slice.len() >= 3);
143 Self::new(slice[0], slice[1], slice[2])
144 }
145
146 /// Writes the elements of `self` to the first 3 elements in `slice`.
147 ///
148 /// # Panics
149 ///
150 /// Panics if `slice` is less than 3 elements long.
151 #[inline]
write_to_slice(self, slice: &mut [f32])152 pub fn write_to_slice(self, slice: &mut [f32]) {
153 slice[..3].copy_from_slice(&self.to_array());
154 }
155
156 /// Creates a [`Vec3A`] from the `x`, `y` and `z` elements of `self` discarding `w`.
157 ///
158 /// On architectures where SIMD is supported such as SSE2 on `x86_64` this conversion is a noop.
159 #[inline]
160 #[must_use]
from_vec4(v: Vec4) -> Self161 pub fn from_vec4(v: Vec4) -> Self {
162 Self {
163 x: v.x,
164 y: v.y,
165 z: v.z,
166 }
167 }
168
169 /// Creates a 4D vector from `self` and the given `w` value.
170 #[inline]
171 #[must_use]
extend(self, w: f32) -> Vec4172 pub fn extend(self, w: f32) -> Vec4 {
173 Vec4::new(self.x, self.y, self.z, w)
174 }
175
176 /// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`.
177 ///
178 /// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()].
179 #[inline]
180 #[must_use]
truncate(self) -> Vec2181 pub fn truncate(self) -> Vec2 {
182 use crate::swizzles::Vec3Swizzles;
183 self.xy()
184 }
185
186 /// Creates a 3D vector from `self` with the given value of `x`.
187 #[inline]
188 #[must_use]
with_x(mut self, x: f32) -> Self189 pub fn with_x(mut self, x: f32) -> Self {
190 self.x = x;
191 self
192 }
193
194 /// Creates a 3D vector from `self` with the given value of `y`.
195 #[inline]
196 #[must_use]
with_y(mut self, y: f32) -> Self197 pub fn with_y(mut self, y: f32) -> Self {
198 self.y = y;
199 self
200 }
201
202 /// Creates a 3D vector from `self` with the given value of `z`.
203 #[inline]
204 #[must_use]
with_z(mut self, z: f32) -> Self205 pub fn with_z(mut self, z: f32) -> Self {
206 self.z = z;
207 self
208 }
209
210 /// Computes the dot product of `self` and `rhs`.
211 #[inline]
212 #[must_use]
dot(self, rhs: Self) -> f32213 pub fn dot(self, rhs: Self) -> f32 {
214 (self.x * rhs.x) + (self.y * rhs.y) + (self.z * rhs.z)
215 }
216
217 /// Returns a vector where every component is the dot product of `self` and `rhs`.
218 #[inline]
219 #[must_use]
dot_into_vec(self, rhs: Self) -> Self220 pub fn dot_into_vec(self, rhs: Self) -> Self {
221 Self::splat(self.dot(rhs))
222 }
223
224 /// Computes the cross product of `self` and `rhs`.
225 #[inline]
226 #[must_use]
cross(self, rhs: Self) -> Self227 pub fn cross(self, rhs: Self) -> Self {
228 Self {
229 x: self.y * rhs.z - rhs.y * self.z,
230 y: self.z * rhs.x - rhs.z * self.x,
231 z: self.x * rhs.y - rhs.x * self.y,
232 }
233 }
234
235 /// Returns a vector containing the minimum values for each element of `self` and `rhs`.
236 ///
237 /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`.
238 #[inline]
239 #[must_use]
min(self, rhs: Self) -> Self240 pub fn min(self, rhs: Self) -> Self {
241 Self {
242 x: self.x.min(rhs.x),
243 y: self.y.min(rhs.y),
244 z: self.z.min(rhs.z),
245 }
246 }
247
248 /// Returns a vector containing the maximum values for each element of `self` and `rhs`.
249 ///
250 /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`.
251 #[inline]
252 #[must_use]
max(self, rhs: Self) -> Self253 pub fn max(self, rhs: Self) -> Self {
254 Self {
255 x: self.x.max(rhs.x),
256 y: self.y.max(rhs.y),
257 z: self.z.max(rhs.z),
258 }
259 }
260
261 /// Component-wise clamping of values, similar to [`f32::clamp`].
262 ///
263 /// Each element in `min` must be less-or-equal to the corresponding element in `max`.
264 ///
265 /// # Panics
266 ///
267 /// Will panic if `min` is greater than `max` when `glam_assert` is enabled.
268 #[inline]
269 #[must_use]
clamp(self, min: Self, max: Self) -> Self270 pub fn clamp(self, min: Self, max: Self) -> Self {
271 glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
272 self.max(min).min(max)
273 }
274
275 /// Returns the horizontal minimum of `self`.
276 ///
277 /// In other words this computes `min(x, y, ..)`.
278 #[inline]
279 #[must_use]
min_element(self) -> f32280 pub fn min_element(self) -> f32 {
281 self.x.min(self.y.min(self.z))
282 }
283
284 /// Returns the horizontal maximum of `self`.
285 ///
286 /// In other words this computes `max(x, y, ..)`.
287 #[inline]
288 #[must_use]
max_element(self) -> f32289 pub fn max_element(self) -> f32 {
290 self.x.max(self.y.max(self.z))
291 }
292
293 /// Returns the sum of all elements of `self`.
294 ///
295 /// In other words, this computes `self.x + self.y + ..`.
296 #[inline]
297 #[must_use]
element_sum(self) -> f32298 pub fn element_sum(self) -> f32 {
299 self.x + self.y + self.z
300 }
301
302 /// Returns the product of all elements of `self`.
303 ///
304 /// In other words, this computes `self.x * self.y * ..`.
305 #[inline]
306 #[must_use]
element_product(self) -> f32307 pub fn element_product(self) -> f32 {
308 self.x * self.y * self.z
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]
cmpeq(self, rhs: Self) -> BVec3A318 pub fn cmpeq(self, rhs: Self) -> BVec3A {
319 BVec3A::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y), self.z.eq(&rhs.z))
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]
cmpne(self, rhs: Self) -> BVec3A329 pub fn cmpne(self, rhs: Self) -> BVec3A {
330 BVec3A::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y), self.z.ne(&rhs.z))
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]
cmpge(self, rhs: Self) -> BVec3A340 pub fn cmpge(self, rhs: Self) -> BVec3A {
341 BVec3A::new(self.x.ge(&rhs.x), self.y.ge(&rhs.y), self.z.ge(&rhs.z))
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]
cmpgt(self, rhs: Self) -> BVec3A351 pub fn cmpgt(self, rhs: Self) -> BVec3A {
352 BVec3A::new(self.x.gt(&rhs.x), self.y.gt(&rhs.y), self.z.gt(&rhs.z))
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]
cmple(self, rhs: Self) -> BVec3A362 pub fn cmple(self, rhs: Self) -> BVec3A {
363 BVec3A::new(self.x.le(&rhs.x), self.y.le(&rhs.y), self.z.le(&rhs.z))
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]
cmplt(self, rhs: Self) -> BVec3A373 pub fn cmplt(self, rhs: Self) -> BVec3A {
374 BVec3A::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y), self.z.lt(&rhs.z))
375 }
376
377 /// Returns a vector containing the absolute value of each element of `self`.
378 #[inline]
379 #[must_use]
abs(self) -> Self380 pub fn abs(self) -> Self {
381 Self {
382 x: math::abs(self.x),
383 y: math::abs(self.y),
384 z: math::abs(self.z),
385 }
386 }
387
388 /// Returns a vector with elements representing the sign of `self`.
389 ///
390 /// - `1.0` if the number is positive, `+0.0` or `INFINITY`
391 /// - `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY`
392 /// - `NAN` if the number is `NAN`
393 #[inline]
394 #[must_use]
signum(self) -> Self395 pub fn signum(self) -> Self {
396 Self {
397 x: math::signum(self.x),
398 y: math::signum(self.y),
399 z: math::signum(self.z),
400 }
401 }
402
403 /// Returns a vector with signs of `rhs` and the magnitudes of `self`.
404 #[inline]
405 #[must_use]
copysign(self, rhs: Self) -> Self406 pub fn copysign(self, rhs: Self) -> Self {
407 Self {
408 x: math::copysign(self.x, rhs.x),
409 y: math::copysign(self.y, rhs.y),
410 z: math::copysign(self.z, rhs.z),
411 }
412 }
413
414 /// Returns a bitmask with the lowest 3 bits set to the sign bits from the elements of `self`.
415 ///
416 /// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes
417 /// into the first lowest bit, element `y` into the second, etc.
418 #[inline]
419 #[must_use]
is_negative_bitmask(self) -> u32420 pub fn is_negative_bitmask(self) -> u32 {
421 (self.x.is_sign_negative() as u32)
422 | (self.y.is_sign_negative() as u32) << 1
423 | (self.z.is_sign_negative() as u32) << 2
424 }
425
426 /// Returns `true` if, and only if, all elements are finite. If any element is either
427 /// `NaN`, positive or negative infinity, this will return `false`.
428 #[inline]
429 #[must_use]
is_finite(self) -> bool430 pub fn is_finite(self) -> bool {
431 self.x.is_finite() && self.y.is_finite() && self.z.is_finite()
432 }
433
434 /// Performs `is_finite` on each element of self, returning a vector mask of the results.
435 ///
436 /// In other words, this computes `[x.is_finite(), y.is_finite(), ...]`.
is_finite_mask(self) -> BVec3A437 pub fn is_finite_mask(self) -> BVec3A {
438 BVec3A::new(self.x.is_finite(), self.y.is_finite(), self.z.is_finite())
439 }
440
441 /// Returns `true` if any elements are `NaN`.
442 #[inline]
443 #[must_use]
is_nan(self) -> bool444 pub fn is_nan(self) -> bool {
445 self.x.is_nan() || self.y.is_nan() || self.z.is_nan()
446 }
447
448 /// Performs `is_nan` on each element of self, returning a vector mask of the results.
449 ///
450 /// In other words, this computes `[x.is_nan(), y.is_nan(), ...]`.
451 #[inline]
452 #[must_use]
is_nan_mask(self) -> BVec3A453 pub fn is_nan_mask(self) -> BVec3A {
454 BVec3A::new(self.x.is_nan(), self.y.is_nan(), self.z.is_nan())
455 }
456
457 /// Computes the length of `self`.
458 #[doc(alias = "magnitude")]
459 #[inline]
460 #[must_use]
length(self) -> f32461 pub fn length(self) -> f32 {
462 math::sqrt(self.dot(self))
463 }
464
465 /// Computes the squared length of `self`.
466 ///
467 /// This is faster than `length()` as it avoids a square root operation.
468 #[doc(alias = "magnitude2")]
469 #[inline]
470 #[must_use]
length_squared(self) -> f32471 pub fn length_squared(self) -> f32 {
472 self.dot(self)
473 }
474
475 /// Computes `1.0 / length()`.
476 ///
477 /// For valid results, `self` must _not_ be of length zero.
478 #[inline]
479 #[must_use]
length_recip(self) -> f32480 pub fn length_recip(self) -> f32 {
481 self.length().recip()
482 }
483
484 /// Computes the Euclidean distance between two points in space.
485 #[inline]
486 #[must_use]
distance(self, rhs: Self) -> f32487 pub fn distance(self, rhs: Self) -> f32 {
488 (self - rhs).length()
489 }
490
491 /// Compute the squared euclidean distance between two points in space.
492 #[inline]
493 #[must_use]
distance_squared(self, rhs: Self) -> f32494 pub fn distance_squared(self, rhs: Self) -> f32 {
495 (self - rhs).length_squared()
496 }
497
498 /// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`.
499 #[inline]
500 #[must_use]
div_euclid(self, rhs: Self) -> Self501 pub fn div_euclid(self, rhs: Self) -> Self {
502 Self::new(
503 math::div_euclid(self.x, rhs.x),
504 math::div_euclid(self.y, rhs.y),
505 math::div_euclid(self.z, rhs.z),
506 )
507 }
508
509 /// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`.
510 ///
511 /// [Euclidean division]: f32::rem_euclid
512 #[inline]
513 #[must_use]
rem_euclid(self, rhs: Self) -> Self514 pub fn rem_euclid(self, rhs: Self) -> Self {
515 Self::new(
516 math::rem_euclid(self.x, rhs.x),
517 math::rem_euclid(self.y, rhs.y),
518 math::rem_euclid(self.z, rhs.z),
519 )
520 }
521
522 /// Returns `self` normalized to length 1.0.
523 ///
524 /// For valid results, `self` must be finite and _not_ of length zero, nor very close to zero.
525 ///
526 /// See also [`Self::try_normalize()`] and [`Self::normalize_or_zero()`].
527 ///
528 /// Panics
529 ///
530 /// Will panic if the resulting normalized vector is not finite when `glam_assert` is enabled.
531 #[inline]
532 #[must_use]
normalize(self) -> Self533 pub fn normalize(self) -> Self {
534 #[allow(clippy::let_and_return)]
535 let normalized = self.mul(self.length_recip());
536 glam_assert!(normalized.is_finite());
537 normalized
538 }
539
540 /// Returns `self` normalized to length 1.0 if possible, else returns `None`.
541 ///
542 /// In particular, if the input is zero (or very close to zero), or non-finite,
543 /// the result of this operation will be `None`.
544 ///
545 /// See also [`Self::normalize_or_zero()`].
546 #[inline]
547 #[must_use]
try_normalize(self) -> Option<Self>548 pub fn try_normalize(self) -> Option<Self> {
549 let rcp = self.length_recip();
550 if rcp.is_finite() && rcp > 0.0 {
551 Some(self * rcp)
552 } else {
553 None
554 }
555 }
556
557 /// Returns `self` normalized to length 1.0 if possible, else returns a
558 /// fallback value.
559 ///
560 /// In particular, if the input is zero (or very close to zero), or non-finite,
561 /// the result of this operation will be the fallback value.
562 ///
563 /// See also [`Self::try_normalize()`].
564 #[inline]
565 #[must_use]
normalize_or(self, fallback: Self) -> Self566 pub fn normalize_or(self, fallback: Self) -> Self {
567 let rcp = self.length_recip();
568 if rcp.is_finite() && rcp > 0.0 {
569 self * rcp
570 } else {
571 fallback
572 }
573 }
574
575 /// Returns `self` normalized to length 1.0 if possible, else returns zero.
576 ///
577 /// In particular, if the input is zero (or very close to zero), or non-finite,
578 /// the result of this operation will be zero.
579 ///
580 /// See also [`Self::try_normalize()`].
581 #[inline]
582 #[must_use]
normalize_or_zero(self) -> Self583 pub fn normalize_or_zero(self) -> Self {
584 self.normalize_or(Self::ZERO)
585 }
586
587 /// Returns whether `self` is length `1.0` or not.
588 ///
589 /// Uses a precision threshold of approximately `1e-4`.
590 #[inline]
591 #[must_use]
is_normalized(self) -> bool592 pub fn is_normalized(self) -> bool {
593 math::abs(self.length_squared() - 1.0) <= 2e-4
594 }
595
596 /// Returns the vector projection of `self` onto `rhs`.
597 ///
598 /// `rhs` must be of non-zero length.
599 ///
600 /// # Panics
601 ///
602 /// Will panic if `rhs` is zero length when `glam_assert` is enabled.
603 #[inline]
604 #[must_use]
project_onto(self, rhs: Self) -> Self605 pub fn project_onto(self, rhs: Self) -> Self {
606 let other_len_sq_rcp = rhs.dot(rhs).recip();
607 glam_assert!(other_len_sq_rcp.is_finite());
608 rhs * self.dot(rhs) * other_len_sq_rcp
609 }
610
611 /// Returns the vector rejection of `self` from `rhs`.
612 ///
613 /// The vector rejection is the vector perpendicular to the projection of `self` onto
614 /// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`.
615 ///
616 /// `rhs` must be of non-zero length.
617 ///
618 /// # Panics
619 ///
620 /// Will panic if `rhs` has a length of zero when `glam_assert` is enabled.
621 #[doc(alias("plane"))]
622 #[inline]
623 #[must_use]
reject_from(self, rhs: Self) -> Self624 pub fn reject_from(self, rhs: Self) -> Self {
625 self - self.project_onto(rhs)
626 }
627
628 /// Returns the vector projection of `self` onto `rhs`.
629 ///
630 /// `rhs` must be normalized.
631 ///
632 /// # Panics
633 ///
634 /// Will panic if `rhs` is not normalized when `glam_assert` is enabled.
635 #[inline]
636 #[must_use]
project_onto_normalized(self, rhs: Self) -> Self637 pub fn project_onto_normalized(self, rhs: Self) -> Self {
638 glam_assert!(rhs.is_normalized());
639 rhs * self.dot(rhs)
640 }
641
642 /// Returns the vector rejection of `self` from `rhs`.
643 ///
644 /// The vector rejection is the vector perpendicular to the projection of `self` onto
645 /// `rhs`, in rhs words the result of `self - self.project_onto(rhs)`.
646 ///
647 /// `rhs` must be normalized.
648 ///
649 /// # Panics
650 ///
651 /// Will panic if `rhs` is not normalized when `glam_assert` is enabled.
652 #[doc(alias("plane"))]
653 #[inline]
654 #[must_use]
reject_from_normalized(self, rhs: Self) -> Self655 pub fn reject_from_normalized(self, rhs: Self) -> Self {
656 self - self.project_onto_normalized(rhs)
657 }
658
659 /// Returns a vector containing the nearest integer to a number for each element of `self`.
660 /// Round half-way cases away from 0.0.
661 #[inline]
662 #[must_use]
round(self) -> Self663 pub fn round(self) -> Self {
664 Self {
665 x: math::round(self.x),
666 y: math::round(self.y),
667 z: math::round(self.z),
668 }
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]
floor(self) -> Self675 pub fn floor(self) -> Self {
676 Self {
677 x: math::floor(self.x),
678 y: math::floor(self.y),
679 z: math::floor(self.z),
680 }
681 }
682
683 /// Returns a vector containing the smallest integer greater than or equal to a number for
684 /// each element of `self`.
685 #[inline]
686 #[must_use]
ceil(self) -> Self687 pub fn ceil(self) -> Self {
688 Self {
689 x: math::ceil(self.x),
690 y: math::ceil(self.y),
691 z: math::ceil(self.z),
692 }
693 }
694
695 /// Returns a vector containing the integer part each element of `self`. This means numbers are
696 /// always truncated towards zero.
697 #[inline]
698 #[must_use]
trunc(self) -> Self699 pub fn trunc(self) -> Self {
700 Self {
701 x: math::trunc(self.x),
702 y: math::trunc(self.y),
703 z: math::trunc(self.z),
704 }
705 }
706
707 /// Returns a vector containing the fractional part of the vector as `self - self.trunc()`.
708 ///
709 /// Note that this differs from the GLSL implementation of `fract` which returns
710 /// `self - self.floor()`.
711 ///
712 /// Note that this is fast but not precise for large numbers.
713 #[inline]
714 #[must_use]
fract(self) -> Self715 pub fn fract(self) -> Self {
716 self - self.trunc()
717 }
718
719 /// Returns a vector containing the fractional part of the vector as `self - self.floor()`.
720 ///
721 /// Note that this differs from the Rust implementation of `fract` which returns
722 /// `self - self.trunc()`.
723 ///
724 /// Note that this is fast but not precise for large numbers.
725 #[inline]
726 #[must_use]
fract_gl(self) -> Self727 pub fn fract_gl(self) -> Self {
728 self - self.floor()
729 }
730
731 /// Returns a vector containing `e^self` (the exponential function) for each element of
732 /// `self`.
733 #[inline]
734 #[must_use]
exp(self) -> Self735 pub fn exp(self) -> Self {
736 Self::new(math::exp(self.x), math::exp(self.y), math::exp(self.z))
737 }
738
739 /// Returns a vector containing each element of `self` raised to the power of `n`.
740 #[inline]
741 #[must_use]
powf(self, n: f32) -> Self742 pub fn powf(self, n: f32) -> Self {
743 Self::new(
744 math::powf(self.x, n),
745 math::powf(self.y, n),
746 math::powf(self.z, n),
747 )
748 }
749
750 /// Returns a vector containing the reciprocal `1.0/n` of each element of `self`.
751 #[inline]
752 #[must_use]
recip(self) -> Self753 pub fn recip(self) -> Self {
754 Self {
755 x: 1.0 / self.x,
756 y: 1.0 / self.y,
757 z: 1.0 / self.z,
758 }
759 }
760
761 /// Performs a linear interpolation between `self` and `rhs` based on the value `s`.
762 ///
763 /// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result
764 /// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly
765 /// extrapolated.
766 #[doc(alias = "mix")]
767 #[inline]
768 #[must_use]
lerp(self, rhs: Self, s: f32) -> Self769 pub fn lerp(self, rhs: Self, s: f32) -> Self {
770 self * (1.0 - s) + rhs * s
771 }
772
773 /// Moves towards `rhs` based on the value `d`.
774 ///
775 /// When `d` is `0.0`, the result will be equal to `self`. When `d` is equal to
776 /// `self.distance(rhs)`, the result will be equal to `rhs`. Will not go past `rhs`.
777 #[inline]
778 #[must_use]
move_towards(&self, rhs: Self, d: f32) -> Self779 pub fn move_towards(&self, rhs: Self, d: f32) -> Self {
780 let a = rhs - *self;
781 let len = a.length();
782 if len <= d || len <= 1e-4 {
783 return rhs;
784 }
785 *self + a / len * d
786 }
787
788 /// Calculates the midpoint between `self` and `rhs`.
789 ///
790 /// The midpoint is the average of, or halfway point between, two vectors.
791 /// `a.midpoint(b)` should yield the same result as `a.lerp(b, 0.5)`
792 /// while being slightly cheaper to compute.
793 #[inline]
midpoint(self, rhs: Self) -> Self794 pub fn midpoint(self, rhs: Self) -> Self {
795 (self + rhs) * 0.5
796 }
797
798 /// Returns true if the absolute difference of all elements between `self` and `rhs` is
799 /// less than or equal to `max_abs_diff`.
800 ///
801 /// This can be used to compare if two vectors contain similar elements. It works best when
802 /// comparing with a known value. The `max_abs_diff` that should be used used depends on
803 /// the values being compared against.
804 ///
805 /// For more see
806 /// [comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/).
807 #[inline]
808 #[must_use]
abs_diff_eq(self, rhs: Self, max_abs_diff: f32) -> bool809 pub fn abs_diff_eq(self, rhs: Self, max_abs_diff: f32) -> bool {
810 self.sub(rhs).abs().cmple(Self::splat(max_abs_diff)).all()
811 }
812
813 /// Returns a vector with a length no less than `min` and no more than `max`.
814 ///
815 /// # Panics
816 ///
817 /// Will panic if `min` is greater than `max`, or if either `min` or `max` is negative, when `glam_assert` is enabled.
818 #[inline]
819 #[must_use]
clamp_length(self, min: f32, max: f32) -> Self820 pub fn clamp_length(self, min: f32, max: f32) -> Self {
821 glam_assert!(0.0 <= min);
822 glam_assert!(min <= max);
823 let length_sq = self.length_squared();
824 if length_sq < min * min {
825 min * (self / math::sqrt(length_sq))
826 } else if length_sq > max * max {
827 max * (self / math::sqrt(length_sq))
828 } else {
829 self
830 }
831 }
832
833 /// Returns a vector with a length no more than `max`.
834 ///
835 /// # Panics
836 ///
837 /// Will panic if `max` is negative when `glam_assert` is enabled.
838 #[inline]
839 #[must_use]
clamp_length_max(self, max: f32) -> Self840 pub fn clamp_length_max(self, max: f32) -> Self {
841 glam_assert!(0.0 <= max);
842 let length_sq = self.length_squared();
843 if length_sq > max * max {
844 max * (self / math::sqrt(length_sq))
845 } else {
846 self
847 }
848 }
849
850 /// Returns a vector with a length no less than `min`.
851 ///
852 /// # Panics
853 ///
854 /// Will panic if `min` is negative when `glam_assert` is enabled.
855 #[inline]
856 #[must_use]
clamp_length_min(self, min: f32) -> Self857 pub fn clamp_length_min(self, min: f32) -> Self {
858 glam_assert!(0.0 <= min);
859 let length_sq = self.length_squared();
860 if length_sq < min * min {
861 min * (self / math::sqrt(length_sq))
862 } else {
863 self
864 }
865 }
866
867 /// Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding
868 /// error, yielding a more accurate result than an unfused multiply-add.
869 ///
870 /// Using `mul_add` *may* be more performant than an unfused multiply-add if the target
871 /// architecture has a dedicated fma CPU instruction. However, this is not always true,
872 /// and will be heavily dependant on designing algorithms with specific target hardware in
873 /// mind.
874 #[inline]
875 #[must_use]
mul_add(self, a: Self, b: Self) -> Self876 pub fn mul_add(self, a: Self, b: Self) -> Self {
877 Self::new(
878 math::mul_add(self.x, a.x, b.x),
879 math::mul_add(self.y, a.y, b.y),
880 math::mul_add(self.z, a.z, b.z),
881 )
882 }
883
884 /// Returns the reflection vector for a given incident vector `self` and surface normal
885 /// `normal`.
886 ///
887 /// `normal` must be normalized.
888 ///
889 /// # Panics
890 ///
891 /// Will panic if `normal` is not normalized when `glam_assert` is enabled.
892 #[inline]
893 #[must_use]
reflect(self, normal: Self) -> Self894 pub fn reflect(self, normal: Self) -> Self {
895 glam_assert!(normal.is_normalized());
896 self - 2.0 * self.dot(normal) * normal
897 }
898
899 /// Returns the refraction direction for a given incident vector `self`, surface normal
900 /// `normal` and ratio of indices of refraction, `eta`. When total internal reflection occurs,
901 /// a zero vector will be returned.
902 ///
903 /// `self` and `normal` must be normalized.
904 ///
905 /// # Panics
906 ///
907 /// Will panic if `self` or `normal` is not normalized when `glam_assert` is enabled.
908 #[inline]
909 #[must_use]
refract(self, normal: Self, eta: f32) -> Self910 pub fn refract(self, normal: Self, eta: f32) -> Self {
911 glam_assert!(self.is_normalized());
912 glam_assert!(normal.is_normalized());
913 let n_dot_i = normal.dot(self);
914 let k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
915 if k >= 0.0 {
916 eta * self - (eta * n_dot_i + math::sqrt(k)) * normal
917 } else {
918 Self::ZERO
919 }
920 }
921
922 /// Returns the angle (in radians) between two vectors in the range `[0, +π]`.
923 ///
924 /// The inputs do not need to be unit vectors however they must be non-zero.
925 #[inline]
926 #[must_use]
angle_between(self, rhs: Self) -> f32927 pub fn angle_between(self, rhs: Self) -> f32 {
928 math::acos_approx(
929 self.dot(rhs)
930 .div(math::sqrt(self.length_squared().mul(rhs.length_squared()))),
931 )
932 }
933
934 /// Returns some vector that is orthogonal to the given one.
935 ///
936 /// The input vector must be finite and non-zero.
937 ///
938 /// The output vector is not necessarily unit length. For that use
939 /// [`Self::any_orthonormal_vector()`] instead.
940 #[inline]
941 #[must_use]
any_orthogonal_vector(&self) -> Self942 pub fn any_orthogonal_vector(&self) -> Self {
943 // This can probably be optimized
944 if math::abs(self.x) > math::abs(self.y) {
945 Self::new(-self.z, 0.0, self.x) // self.cross(Self::Y)
946 } else {
947 Self::new(0.0, self.z, -self.y) // self.cross(Self::X)
948 }
949 }
950
951 /// Returns any unit vector that is orthogonal to the given one.
952 ///
953 /// The input vector must be unit length.
954 ///
955 /// # Panics
956 ///
957 /// Will panic if `self` is not normalized when `glam_assert` is enabled.
958 #[inline]
959 #[must_use]
any_orthonormal_vector(&self) -> Self960 pub fn any_orthonormal_vector(&self) -> Self {
961 glam_assert!(self.is_normalized());
962 // From https://graphics.pixar.com/library/OrthonormalB/paper.pdf
963 let sign = math::signum(self.z);
964 let a = -1.0 / (sign + self.z);
965 let b = self.x * self.y * a;
966 Self::new(b, sign + self.y * self.y * a, -self.y)
967 }
968
969 /// Given a unit vector return two other vectors that together form an orthonormal
970 /// basis. That is, all three vectors are orthogonal to each other and are normalized.
971 ///
972 /// # Panics
973 ///
974 /// Will panic if `self` is not normalized when `glam_assert` is enabled.
975 #[inline]
976 #[must_use]
any_orthonormal_pair(&self) -> (Self, Self)977 pub fn any_orthonormal_pair(&self) -> (Self, Self) {
978 glam_assert!(self.is_normalized());
979 // From https://graphics.pixar.com/library/OrthonormalB/paper.pdf
980 let sign = math::signum(self.z);
981 let a = -1.0 / (sign + self.z);
982 let b = self.x * self.y * a;
983 (
984 Self::new(1.0 + sign * self.x * self.x * a, sign * b, -sign * self.x),
985 Self::new(b, sign + self.y * self.y * a, -self.y),
986 )
987 }
988
989 /// Performs a spherical linear interpolation between `self` and `rhs` based on the value `s`.
990 ///
991 /// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result
992 /// will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly
993 /// extrapolated.
994 #[inline]
995 #[must_use]
slerp(self, rhs: Self, s: f32) -> Self996 pub fn slerp(self, rhs: Self, s: f32) -> Self {
997 let self_length = self.length();
998 let rhs_length = rhs.length();
999 // Cosine of the angle between the vectors [-1, 1], or NaN if either vector has a zero length
1000 let dot = self.dot(rhs) / (self_length * rhs_length);
1001 // If dot is close to 1 or -1, or is NaN the calculations for t1 and t2 break down
1002 if math::abs(dot) < 1.0 - 3e-7 {
1003 // Angle between the vectors [0, +π]
1004 let theta = math::acos_approx(dot);
1005 // Sine of the angle between vectors [0, 1]
1006 let sin_theta = math::sin(theta);
1007 let t1 = math::sin(theta * (1. - s));
1008 let t2 = math::sin(theta * s);
1009
1010 // Interpolate vector lengths
1011 let result_length = self_length.lerp(rhs_length, s);
1012 // Scale the vectors to the target length and interpolate them
1013 return (self * (result_length / self_length) * t1
1014 + rhs * (result_length / rhs_length) * t2)
1015 * sin_theta.recip();
1016 }
1017 if dot < 0.0 {
1018 // Vectors are almost parallel in opposing directions
1019
1020 // Create a rotation from self to rhs along some axis
1021 let axis = self.any_orthogonal_vector().normalize().into();
1022 let rotation = Quat::from_axis_angle(axis, core::f32::consts::PI * s);
1023 // Interpolate vector lengths
1024 let result_length = self_length.lerp(rhs_length, s);
1025 rotation * self * (result_length / self_length)
1026 } else {
1027 // Vectors are almost parallel in the same direction, or dot was NaN
1028 self.lerp(rhs, s)
1029 }
1030 }
1031
1032 /// Casts all elements of `self` to `f64`.
1033 #[inline]
1034 #[must_use]
as_dvec3(&self) -> crate::DVec31035 pub fn as_dvec3(&self) -> crate::DVec3 {
1036 crate::DVec3::new(self.x as f64, self.y as f64, self.z as f64)
1037 }
1038
1039 /// Casts all elements of `self` to `i8`.
1040 #[inline]
1041 #[must_use]
as_i8vec3(&self) -> crate::I8Vec31042 pub fn as_i8vec3(&self) -> crate::I8Vec3 {
1043 crate::I8Vec3::new(self.x as i8, self.y as i8, self.z as i8)
1044 }
1045
1046 /// Casts all elements of `self` to `u8`.
1047 #[inline]
1048 #[must_use]
as_u8vec3(&self) -> crate::U8Vec31049 pub fn as_u8vec3(&self) -> crate::U8Vec3 {
1050 crate::U8Vec3::new(self.x as u8, self.y as u8, self.z as u8)
1051 }
1052
1053 /// Casts all elements of `self` to `i16`.
1054 #[inline]
1055 #[must_use]
as_i16vec3(&self) -> crate::I16Vec31056 pub fn as_i16vec3(&self) -> crate::I16Vec3 {
1057 crate::I16Vec3::new(self.x as i16, self.y as i16, self.z as i16)
1058 }
1059
1060 /// Casts all elements of `self` to `u16`.
1061 #[inline]
1062 #[must_use]
as_u16vec3(&self) -> crate::U16Vec31063 pub fn as_u16vec3(&self) -> crate::U16Vec3 {
1064 crate::U16Vec3::new(self.x as u16, self.y as u16, self.z as u16)
1065 }
1066
1067 /// Casts all elements of `self` to `i32`.
1068 #[inline]
1069 #[must_use]
as_ivec3(&self) -> crate::IVec31070 pub fn as_ivec3(&self) -> crate::IVec3 {
1071 crate::IVec3::new(self.x as i32, self.y as i32, self.z as i32)
1072 }
1073
1074 /// Casts all elements of `self` to `u32`.
1075 #[inline]
1076 #[must_use]
as_uvec3(&self) -> crate::UVec31077 pub fn as_uvec3(&self) -> crate::UVec3 {
1078 crate::UVec3::new(self.x as u32, self.y as u32, self.z as u32)
1079 }
1080
1081 /// Casts all elements of `self` to `i64`.
1082 #[inline]
1083 #[must_use]
as_i64vec3(&self) -> crate::I64Vec31084 pub fn as_i64vec3(&self) -> crate::I64Vec3 {
1085 crate::I64Vec3::new(self.x as i64, self.y as i64, self.z as i64)
1086 }
1087
1088 /// Casts all elements of `self` to `u64`.
1089 #[inline]
1090 #[must_use]
as_u64vec3(&self) -> crate::U64Vec31091 pub fn as_u64vec3(&self) -> crate::U64Vec3 {
1092 crate::U64Vec3::new(self.x as u64, self.y as u64, self.z as u64)
1093 }
1094 }
1095
1096 impl Default for Vec3A {
1097 #[inline(always)]
default() -> Self1098 fn default() -> Self {
1099 Self::ZERO
1100 }
1101 }
1102
1103 impl Div<Vec3A> for Vec3A {
1104 type Output = Self;
1105 #[inline]
div(self, rhs: Self) -> Self1106 fn div(self, rhs: Self) -> Self {
1107 Self {
1108 x: self.x.div(rhs.x),
1109 y: self.y.div(rhs.y),
1110 z: self.z.div(rhs.z),
1111 }
1112 }
1113 }
1114
1115 impl Div<&Vec3A> for Vec3A {
1116 type Output = Vec3A;
1117 #[inline]
div(self, rhs: &Vec3A) -> Vec3A1118 fn div(self, rhs: &Vec3A) -> Vec3A {
1119 self.div(*rhs)
1120 }
1121 }
1122
1123 impl Div<&Vec3A> for &Vec3A {
1124 type Output = Vec3A;
1125 #[inline]
div(self, rhs: &Vec3A) -> Vec3A1126 fn div(self, rhs: &Vec3A) -> Vec3A {
1127 (*self).div(*rhs)
1128 }
1129 }
1130
1131 impl Div<Vec3A> for &Vec3A {
1132 type Output = Vec3A;
1133 #[inline]
div(self, rhs: Vec3A) -> Vec3A1134 fn div(self, rhs: Vec3A) -> Vec3A {
1135 (*self).div(rhs)
1136 }
1137 }
1138
1139 impl DivAssign<Vec3A> for Vec3A {
1140 #[inline]
div_assign(&mut self, rhs: Self)1141 fn div_assign(&mut self, rhs: Self) {
1142 self.x.div_assign(rhs.x);
1143 self.y.div_assign(rhs.y);
1144 self.z.div_assign(rhs.z);
1145 }
1146 }
1147
1148 impl DivAssign<&Vec3A> for Vec3A {
1149 #[inline]
div_assign(&mut self, rhs: &Vec3A)1150 fn div_assign(&mut self, rhs: &Vec3A) {
1151 self.div_assign(*rhs)
1152 }
1153 }
1154
1155 impl Div<f32> for Vec3A {
1156 type Output = Self;
1157 #[inline]
div(self, rhs: f32) -> Self1158 fn div(self, rhs: f32) -> Self {
1159 Self {
1160 x: self.x.div(rhs),
1161 y: self.y.div(rhs),
1162 z: self.z.div(rhs),
1163 }
1164 }
1165 }
1166
1167 impl Div<&f32> for Vec3A {
1168 type Output = Vec3A;
1169 #[inline]
div(self, rhs: &f32) -> Vec3A1170 fn div(self, rhs: &f32) -> Vec3A {
1171 self.div(*rhs)
1172 }
1173 }
1174
1175 impl Div<&f32> for &Vec3A {
1176 type Output = Vec3A;
1177 #[inline]
div(self, rhs: &f32) -> Vec3A1178 fn div(self, rhs: &f32) -> Vec3A {
1179 (*self).div(*rhs)
1180 }
1181 }
1182
1183 impl Div<f32> for &Vec3A {
1184 type Output = Vec3A;
1185 #[inline]
div(self, rhs: f32) -> Vec3A1186 fn div(self, rhs: f32) -> Vec3A {
1187 (*self).div(rhs)
1188 }
1189 }
1190
1191 impl DivAssign<f32> for Vec3A {
1192 #[inline]
div_assign(&mut self, rhs: f32)1193 fn div_assign(&mut self, rhs: f32) {
1194 self.x.div_assign(rhs);
1195 self.y.div_assign(rhs);
1196 self.z.div_assign(rhs);
1197 }
1198 }
1199
1200 impl DivAssign<&f32> for Vec3A {
1201 #[inline]
div_assign(&mut self, rhs: &f32)1202 fn div_assign(&mut self, rhs: &f32) {
1203 self.div_assign(*rhs)
1204 }
1205 }
1206
1207 impl Div<Vec3A> for f32 {
1208 type Output = Vec3A;
1209 #[inline]
div(self, rhs: Vec3A) -> Vec3A1210 fn div(self, rhs: Vec3A) -> Vec3A {
1211 Vec3A {
1212 x: self.div(rhs.x),
1213 y: self.div(rhs.y),
1214 z: self.div(rhs.z),
1215 }
1216 }
1217 }
1218
1219 impl Div<&Vec3A> for f32 {
1220 type Output = Vec3A;
1221 #[inline]
div(self, rhs: &Vec3A) -> Vec3A1222 fn div(self, rhs: &Vec3A) -> Vec3A {
1223 self.div(*rhs)
1224 }
1225 }
1226
1227 impl Div<&Vec3A> for &f32 {
1228 type Output = Vec3A;
1229 #[inline]
div(self, rhs: &Vec3A) -> Vec3A1230 fn div(self, rhs: &Vec3A) -> Vec3A {
1231 (*self).div(*rhs)
1232 }
1233 }
1234
1235 impl Div<Vec3A> for &f32 {
1236 type Output = Vec3A;
1237 #[inline]
div(self, rhs: Vec3A) -> Vec3A1238 fn div(self, rhs: Vec3A) -> Vec3A {
1239 (*self).div(rhs)
1240 }
1241 }
1242
1243 impl Mul<Vec3A> for Vec3A {
1244 type Output = Self;
1245 #[inline]
mul(self, rhs: Self) -> Self1246 fn mul(self, rhs: Self) -> Self {
1247 Self {
1248 x: self.x.mul(rhs.x),
1249 y: self.y.mul(rhs.y),
1250 z: self.z.mul(rhs.z),
1251 }
1252 }
1253 }
1254
1255 impl Mul<&Vec3A> for Vec3A {
1256 type Output = Vec3A;
1257 #[inline]
mul(self, rhs: &Vec3A) -> Vec3A1258 fn mul(self, rhs: &Vec3A) -> Vec3A {
1259 self.mul(*rhs)
1260 }
1261 }
1262
1263 impl Mul<&Vec3A> for &Vec3A {
1264 type Output = Vec3A;
1265 #[inline]
mul(self, rhs: &Vec3A) -> Vec3A1266 fn mul(self, rhs: &Vec3A) -> Vec3A {
1267 (*self).mul(*rhs)
1268 }
1269 }
1270
1271 impl Mul<Vec3A> for &Vec3A {
1272 type Output = Vec3A;
1273 #[inline]
mul(self, rhs: Vec3A) -> Vec3A1274 fn mul(self, rhs: Vec3A) -> Vec3A {
1275 (*self).mul(rhs)
1276 }
1277 }
1278
1279 impl MulAssign<Vec3A> for Vec3A {
1280 #[inline]
mul_assign(&mut self, rhs: Self)1281 fn mul_assign(&mut self, rhs: Self) {
1282 self.x.mul_assign(rhs.x);
1283 self.y.mul_assign(rhs.y);
1284 self.z.mul_assign(rhs.z);
1285 }
1286 }
1287
1288 impl MulAssign<&Vec3A> for Vec3A {
1289 #[inline]
mul_assign(&mut self, rhs: &Vec3A)1290 fn mul_assign(&mut self, rhs: &Vec3A) {
1291 self.mul_assign(*rhs)
1292 }
1293 }
1294
1295 impl Mul<f32> for Vec3A {
1296 type Output = Self;
1297 #[inline]
mul(self, rhs: f32) -> Self1298 fn mul(self, rhs: f32) -> Self {
1299 Self {
1300 x: self.x.mul(rhs),
1301 y: self.y.mul(rhs),
1302 z: self.z.mul(rhs),
1303 }
1304 }
1305 }
1306
1307 impl Mul<&f32> for Vec3A {
1308 type Output = Vec3A;
1309 #[inline]
mul(self, rhs: &f32) -> Vec3A1310 fn mul(self, rhs: &f32) -> Vec3A {
1311 self.mul(*rhs)
1312 }
1313 }
1314
1315 impl Mul<&f32> for &Vec3A {
1316 type Output = Vec3A;
1317 #[inline]
mul(self, rhs: &f32) -> Vec3A1318 fn mul(self, rhs: &f32) -> Vec3A {
1319 (*self).mul(*rhs)
1320 }
1321 }
1322
1323 impl Mul<f32> for &Vec3A {
1324 type Output = Vec3A;
1325 #[inline]
mul(self, rhs: f32) -> Vec3A1326 fn mul(self, rhs: f32) -> Vec3A {
1327 (*self).mul(rhs)
1328 }
1329 }
1330
1331 impl MulAssign<f32> for Vec3A {
1332 #[inline]
mul_assign(&mut self, rhs: f32)1333 fn mul_assign(&mut self, rhs: f32) {
1334 self.x.mul_assign(rhs);
1335 self.y.mul_assign(rhs);
1336 self.z.mul_assign(rhs);
1337 }
1338 }
1339
1340 impl MulAssign<&f32> for Vec3A {
1341 #[inline]
mul_assign(&mut self, rhs: &f32)1342 fn mul_assign(&mut self, rhs: &f32) {
1343 self.mul_assign(*rhs)
1344 }
1345 }
1346
1347 impl Mul<Vec3A> for f32 {
1348 type Output = Vec3A;
1349 #[inline]
mul(self, rhs: Vec3A) -> Vec3A1350 fn mul(self, rhs: Vec3A) -> Vec3A {
1351 Vec3A {
1352 x: self.mul(rhs.x),
1353 y: self.mul(rhs.y),
1354 z: self.mul(rhs.z),
1355 }
1356 }
1357 }
1358
1359 impl Mul<&Vec3A> for f32 {
1360 type Output = Vec3A;
1361 #[inline]
mul(self, rhs: &Vec3A) -> Vec3A1362 fn mul(self, rhs: &Vec3A) -> Vec3A {
1363 self.mul(*rhs)
1364 }
1365 }
1366
1367 impl Mul<&Vec3A> for &f32 {
1368 type Output = Vec3A;
1369 #[inline]
mul(self, rhs: &Vec3A) -> Vec3A1370 fn mul(self, rhs: &Vec3A) -> Vec3A {
1371 (*self).mul(*rhs)
1372 }
1373 }
1374
1375 impl Mul<Vec3A> for &f32 {
1376 type Output = Vec3A;
1377 #[inline]
mul(self, rhs: Vec3A) -> Vec3A1378 fn mul(self, rhs: Vec3A) -> Vec3A {
1379 (*self).mul(rhs)
1380 }
1381 }
1382
1383 impl Add<Vec3A> for Vec3A {
1384 type Output = Self;
1385 #[inline]
add(self, rhs: Self) -> Self1386 fn add(self, rhs: Self) -> Self {
1387 Self {
1388 x: self.x.add(rhs.x),
1389 y: self.y.add(rhs.y),
1390 z: self.z.add(rhs.z),
1391 }
1392 }
1393 }
1394
1395 impl Add<&Vec3A> for Vec3A {
1396 type Output = Vec3A;
1397 #[inline]
add(self, rhs: &Vec3A) -> Vec3A1398 fn add(self, rhs: &Vec3A) -> Vec3A {
1399 self.add(*rhs)
1400 }
1401 }
1402
1403 impl Add<&Vec3A> for &Vec3A {
1404 type Output = Vec3A;
1405 #[inline]
add(self, rhs: &Vec3A) -> Vec3A1406 fn add(self, rhs: &Vec3A) -> Vec3A {
1407 (*self).add(*rhs)
1408 }
1409 }
1410
1411 impl Add<Vec3A> for &Vec3A {
1412 type Output = Vec3A;
1413 #[inline]
add(self, rhs: Vec3A) -> Vec3A1414 fn add(self, rhs: Vec3A) -> Vec3A {
1415 (*self).add(rhs)
1416 }
1417 }
1418
1419 impl AddAssign<Vec3A> for Vec3A {
1420 #[inline]
add_assign(&mut self, rhs: Self)1421 fn add_assign(&mut self, rhs: Self) {
1422 self.x.add_assign(rhs.x);
1423 self.y.add_assign(rhs.y);
1424 self.z.add_assign(rhs.z);
1425 }
1426 }
1427
1428 impl AddAssign<&Vec3A> for Vec3A {
1429 #[inline]
add_assign(&mut self, rhs: &Vec3A)1430 fn add_assign(&mut self, rhs: &Vec3A) {
1431 self.add_assign(*rhs)
1432 }
1433 }
1434
1435 impl Add<f32> for Vec3A {
1436 type Output = Self;
1437 #[inline]
add(self, rhs: f32) -> Self1438 fn add(self, rhs: f32) -> Self {
1439 Self {
1440 x: self.x.add(rhs),
1441 y: self.y.add(rhs),
1442 z: self.z.add(rhs),
1443 }
1444 }
1445 }
1446
1447 impl Add<&f32> for Vec3A {
1448 type Output = Vec3A;
1449 #[inline]
add(self, rhs: &f32) -> Vec3A1450 fn add(self, rhs: &f32) -> Vec3A {
1451 self.add(*rhs)
1452 }
1453 }
1454
1455 impl Add<&f32> for &Vec3A {
1456 type Output = Vec3A;
1457 #[inline]
add(self, rhs: &f32) -> Vec3A1458 fn add(self, rhs: &f32) -> Vec3A {
1459 (*self).add(*rhs)
1460 }
1461 }
1462
1463 impl Add<f32> for &Vec3A {
1464 type Output = Vec3A;
1465 #[inline]
add(self, rhs: f32) -> Vec3A1466 fn add(self, rhs: f32) -> Vec3A {
1467 (*self).add(rhs)
1468 }
1469 }
1470
1471 impl AddAssign<f32> for Vec3A {
1472 #[inline]
add_assign(&mut self, rhs: f32)1473 fn add_assign(&mut self, rhs: f32) {
1474 self.x.add_assign(rhs);
1475 self.y.add_assign(rhs);
1476 self.z.add_assign(rhs);
1477 }
1478 }
1479
1480 impl AddAssign<&f32> for Vec3A {
1481 #[inline]
add_assign(&mut self, rhs: &f32)1482 fn add_assign(&mut self, rhs: &f32) {
1483 self.add_assign(*rhs)
1484 }
1485 }
1486
1487 impl Add<Vec3A> for f32 {
1488 type Output = Vec3A;
1489 #[inline]
add(self, rhs: Vec3A) -> Vec3A1490 fn add(self, rhs: Vec3A) -> Vec3A {
1491 Vec3A {
1492 x: self.add(rhs.x),
1493 y: self.add(rhs.y),
1494 z: self.add(rhs.z),
1495 }
1496 }
1497 }
1498
1499 impl Add<&Vec3A> for f32 {
1500 type Output = Vec3A;
1501 #[inline]
add(self, rhs: &Vec3A) -> Vec3A1502 fn add(self, rhs: &Vec3A) -> Vec3A {
1503 self.add(*rhs)
1504 }
1505 }
1506
1507 impl Add<&Vec3A> for &f32 {
1508 type Output = Vec3A;
1509 #[inline]
add(self, rhs: &Vec3A) -> Vec3A1510 fn add(self, rhs: &Vec3A) -> Vec3A {
1511 (*self).add(*rhs)
1512 }
1513 }
1514
1515 impl Add<Vec3A> for &f32 {
1516 type Output = Vec3A;
1517 #[inline]
add(self, rhs: Vec3A) -> Vec3A1518 fn add(self, rhs: Vec3A) -> Vec3A {
1519 (*self).add(rhs)
1520 }
1521 }
1522
1523 impl Sub<Vec3A> for Vec3A {
1524 type Output = Self;
1525 #[inline]
sub(self, rhs: Self) -> Self1526 fn sub(self, rhs: Self) -> Self {
1527 Self {
1528 x: self.x.sub(rhs.x),
1529 y: self.y.sub(rhs.y),
1530 z: self.z.sub(rhs.z),
1531 }
1532 }
1533 }
1534
1535 impl Sub<&Vec3A> for Vec3A {
1536 type Output = Vec3A;
1537 #[inline]
sub(self, rhs: &Vec3A) -> Vec3A1538 fn sub(self, rhs: &Vec3A) -> Vec3A {
1539 self.sub(*rhs)
1540 }
1541 }
1542
1543 impl Sub<&Vec3A> for &Vec3A {
1544 type Output = Vec3A;
1545 #[inline]
sub(self, rhs: &Vec3A) -> Vec3A1546 fn sub(self, rhs: &Vec3A) -> Vec3A {
1547 (*self).sub(*rhs)
1548 }
1549 }
1550
1551 impl Sub<Vec3A> for &Vec3A {
1552 type Output = Vec3A;
1553 #[inline]
sub(self, rhs: Vec3A) -> Vec3A1554 fn sub(self, rhs: Vec3A) -> Vec3A {
1555 (*self).sub(rhs)
1556 }
1557 }
1558
1559 impl SubAssign<Vec3A> for Vec3A {
1560 #[inline]
sub_assign(&mut self, rhs: Vec3A)1561 fn sub_assign(&mut self, rhs: Vec3A) {
1562 self.x.sub_assign(rhs.x);
1563 self.y.sub_assign(rhs.y);
1564 self.z.sub_assign(rhs.z);
1565 }
1566 }
1567
1568 impl SubAssign<&Vec3A> for Vec3A {
1569 #[inline]
sub_assign(&mut self, rhs: &Vec3A)1570 fn sub_assign(&mut self, rhs: &Vec3A) {
1571 self.sub_assign(*rhs)
1572 }
1573 }
1574
1575 impl Sub<f32> for Vec3A {
1576 type Output = Self;
1577 #[inline]
sub(self, rhs: f32) -> Self1578 fn sub(self, rhs: f32) -> Self {
1579 Self {
1580 x: self.x.sub(rhs),
1581 y: self.y.sub(rhs),
1582 z: self.z.sub(rhs),
1583 }
1584 }
1585 }
1586
1587 impl Sub<&f32> for Vec3A {
1588 type Output = Vec3A;
1589 #[inline]
sub(self, rhs: &f32) -> Vec3A1590 fn sub(self, rhs: &f32) -> Vec3A {
1591 self.sub(*rhs)
1592 }
1593 }
1594
1595 impl Sub<&f32> for &Vec3A {
1596 type Output = Vec3A;
1597 #[inline]
sub(self, rhs: &f32) -> Vec3A1598 fn sub(self, rhs: &f32) -> Vec3A {
1599 (*self).sub(*rhs)
1600 }
1601 }
1602
1603 impl Sub<f32> for &Vec3A {
1604 type Output = Vec3A;
1605 #[inline]
sub(self, rhs: f32) -> Vec3A1606 fn sub(self, rhs: f32) -> Vec3A {
1607 (*self).sub(rhs)
1608 }
1609 }
1610
1611 impl SubAssign<f32> for Vec3A {
1612 #[inline]
sub_assign(&mut self, rhs: f32)1613 fn sub_assign(&mut self, rhs: f32) {
1614 self.x.sub_assign(rhs);
1615 self.y.sub_assign(rhs);
1616 self.z.sub_assign(rhs);
1617 }
1618 }
1619
1620 impl SubAssign<&f32> for Vec3A {
1621 #[inline]
sub_assign(&mut self, rhs: &f32)1622 fn sub_assign(&mut self, rhs: &f32) {
1623 self.sub_assign(*rhs)
1624 }
1625 }
1626
1627 impl Sub<Vec3A> for f32 {
1628 type Output = Vec3A;
1629 #[inline]
sub(self, rhs: Vec3A) -> Vec3A1630 fn sub(self, rhs: Vec3A) -> Vec3A {
1631 Vec3A {
1632 x: self.sub(rhs.x),
1633 y: self.sub(rhs.y),
1634 z: self.sub(rhs.z),
1635 }
1636 }
1637 }
1638
1639 impl Sub<&Vec3A> for f32 {
1640 type Output = Vec3A;
1641 #[inline]
sub(self, rhs: &Vec3A) -> Vec3A1642 fn sub(self, rhs: &Vec3A) -> Vec3A {
1643 self.sub(*rhs)
1644 }
1645 }
1646
1647 impl Sub<&Vec3A> for &f32 {
1648 type Output = Vec3A;
1649 #[inline]
sub(self, rhs: &Vec3A) -> Vec3A1650 fn sub(self, rhs: &Vec3A) -> Vec3A {
1651 (*self).sub(*rhs)
1652 }
1653 }
1654
1655 impl Sub<Vec3A> for &f32 {
1656 type Output = Vec3A;
1657 #[inline]
sub(self, rhs: Vec3A) -> Vec3A1658 fn sub(self, rhs: Vec3A) -> Vec3A {
1659 (*self).sub(rhs)
1660 }
1661 }
1662
1663 impl Rem<Vec3A> for Vec3A {
1664 type Output = Self;
1665 #[inline]
rem(self, rhs: Self) -> Self1666 fn rem(self, rhs: Self) -> Self {
1667 Self {
1668 x: self.x.rem(rhs.x),
1669 y: self.y.rem(rhs.y),
1670 z: self.z.rem(rhs.z),
1671 }
1672 }
1673 }
1674
1675 impl Rem<&Vec3A> for Vec3A {
1676 type Output = Vec3A;
1677 #[inline]
rem(self, rhs: &Vec3A) -> Vec3A1678 fn rem(self, rhs: &Vec3A) -> Vec3A {
1679 self.rem(*rhs)
1680 }
1681 }
1682
1683 impl Rem<&Vec3A> for &Vec3A {
1684 type Output = Vec3A;
1685 #[inline]
rem(self, rhs: &Vec3A) -> Vec3A1686 fn rem(self, rhs: &Vec3A) -> Vec3A {
1687 (*self).rem(*rhs)
1688 }
1689 }
1690
1691 impl Rem<Vec3A> for &Vec3A {
1692 type Output = Vec3A;
1693 #[inline]
rem(self, rhs: Vec3A) -> Vec3A1694 fn rem(self, rhs: Vec3A) -> Vec3A {
1695 (*self).rem(rhs)
1696 }
1697 }
1698
1699 impl RemAssign<Vec3A> for Vec3A {
1700 #[inline]
rem_assign(&mut self, rhs: Self)1701 fn rem_assign(&mut self, rhs: Self) {
1702 self.x.rem_assign(rhs.x);
1703 self.y.rem_assign(rhs.y);
1704 self.z.rem_assign(rhs.z);
1705 }
1706 }
1707
1708 impl RemAssign<&Vec3A> for Vec3A {
1709 #[inline]
rem_assign(&mut self, rhs: &Vec3A)1710 fn rem_assign(&mut self, rhs: &Vec3A) {
1711 self.rem_assign(*rhs)
1712 }
1713 }
1714
1715 impl Rem<f32> for Vec3A {
1716 type Output = Self;
1717 #[inline]
rem(self, rhs: f32) -> Self1718 fn rem(self, rhs: f32) -> Self {
1719 Self {
1720 x: self.x.rem(rhs),
1721 y: self.y.rem(rhs),
1722 z: self.z.rem(rhs),
1723 }
1724 }
1725 }
1726
1727 impl Rem<&f32> for Vec3A {
1728 type Output = Vec3A;
1729 #[inline]
rem(self, rhs: &f32) -> Vec3A1730 fn rem(self, rhs: &f32) -> Vec3A {
1731 self.rem(*rhs)
1732 }
1733 }
1734
1735 impl Rem<&f32> for &Vec3A {
1736 type Output = Vec3A;
1737 #[inline]
rem(self, rhs: &f32) -> Vec3A1738 fn rem(self, rhs: &f32) -> Vec3A {
1739 (*self).rem(*rhs)
1740 }
1741 }
1742
1743 impl Rem<f32> for &Vec3A {
1744 type Output = Vec3A;
1745 #[inline]
rem(self, rhs: f32) -> Vec3A1746 fn rem(self, rhs: f32) -> Vec3A {
1747 (*self).rem(rhs)
1748 }
1749 }
1750
1751 impl RemAssign<f32> for Vec3A {
1752 #[inline]
rem_assign(&mut self, rhs: f32)1753 fn rem_assign(&mut self, rhs: f32) {
1754 self.x.rem_assign(rhs);
1755 self.y.rem_assign(rhs);
1756 self.z.rem_assign(rhs);
1757 }
1758 }
1759
1760 impl RemAssign<&f32> for Vec3A {
1761 #[inline]
rem_assign(&mut self, rhs: &f32)1762 fn rem_assign(&mut self, rhs: &f32) {
1763 self.rem_assign(*rhs)
1764 }
1765 }
1766
1767 impl Rem<Vec3A> for f32 {
1768 type Output = Vec3A;
1769 #[inline]
rem(self, rhs: Vec3A) -> Vec3A1770 fn rem(self, rhs: Vec3A) -> Vec3A {
1771 Vec3A {
1772 x: self.rem(rhs.x),
1773 y: self.rem(rhs.y),
1774 z: self.rem(rhs.z),
1775 }
1776 }
1777 }
1778
1779 impl Rem<&Vec3A> for f32 {
1780 type Output = Vec3A;
1781 #[inline]
rem(self, rhs: &Vec3A) -> Vec3A1782 fn rem(self, rhs: &Vec3A) -> Vec3A {
1783 self.rem(*rhs)
1784 }
1785 }
1786
1787 impl Rem<&Vec3A> for &f32 {
1788 type Output = Vec3A;
1789 #[inline]
rem(self, rhs: &Vec3A) -> Vec3A1790 fn rem(self, rhs: &Vec3A) -> Vec3A {
1791 (*self).rem(*rhs)
1792 }
1793 }
1794
1795 impl Rem<Vec3A> for &f32 {
1796 type Output = Vec3A;
1797 #[inline]
rem(self, rhs: Vec3A) -> Vec3A1798 fn rem(self, rhs: Vec3A) -> Vec3A {
1799 (*self).rem(rhs)
1800 }
1801 }
1802
1803 #[cfg(not(target_arch = "spirv"))]
1804 impl AsRef<[f32; 3]> for Vec3A {
1805 #[inline]
as_ref(&self) -> &[f32; 3]1806 fn as_ref(&self) -> &[f32; 3] {
1807 unsafe { &*(self as *const Vec3A as *const [f32; 3]) }
1808 }
1809 }
1810
1811 #[cfg(not(target_arch = "spirv"))]
1812 impl AsMut<[f32; 3]> for Vec3A {
1813 #[inline]
as_mut(&mut self) -> &mut [f32; 3]1814 fn as_mut(&mut self) -> &mut [f32; 3] {
1815 unsafe { &mut *(self as *mut Vec3A as *mut [f32; 3]) }
1816 }
1817 }
1818
1819 impl Sum for Vec3A {
1820 #[inline]
sum<I>(iter: I) -> Self where I: Iterator<Item = Self>,1821 fn sum<I>(iter: I) -> Self
1822 where
1823 I: Iterator<Item = Self>,
1824 {
1825 iter.fold(Self::ZERO, Self::add)
1826 }
1827 }
1828
1829 impl<'a> Sum<&'a Self> for Vec3A {
1830 #[inline]
sum<I>(iter: I) -> Self where I: Iterator<Item = &'a Self>,1831 fn sum<I>(iter: I) -> Self
1832 where
1833 I: Iterator<Item = &'a Self>,
1834 {
1835 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
1836 }
1837 }
1838
1839 impl Product for Vec3A {
1840 #[inline]
product<I>(iter: I) -> Self where I: Iterator<Item = Self>,1841 fn product<I>(iter: I) -> Self
1842 where
1843 I: Iterator<Item = Self>,
1844 {
1845 iter.fold(Self::ONE, Self::mul)
1846 }
1847 }
1848
1849 impl<'a> Product<&'a Self> for Vec3A {
1850 #[inline]
product<I>(iter: I) -> Self where I: Iterator<Item = &'a Self>,1851 fn product<I>(iter: I) -> Self
1852 where
1853 I: Iterator<Item = &'a Self>,
1854 {
1855 iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
1856 }
1857 }
1858
1859 impl Neg for Vec3A {
1860 type Output = Self;
1861 #[inline]
neg(self) -> Self1862 fn neg(self) -> Self {
1863 Self {
1864 x: self.x.neg(),
1865 y: self.y.neg(),
1866 z: self.z.neg(),
1867 }
1868 }
1869 }
1870
1871 impl Neg for &Vec3A {
1872 type Output = Vec3A;
1873 #[inline]
neg(self) -> Vec3A1874 fn neg(self) -> Vec3A {
1875 (*self).neg()
1876 }
1877 }
1878
1879 impl Index<usize> for Vec3A {
1880 type Output = f32;
1881 #[inline]
index(&self, index: usize) -> &Self::Output1882 fn index(&self, index: usize) -> &Self::Output {
1883 match index {
1884 0 => &self.x,
1885 1 => &self.y,
1886 2 => &self.z,
1887 _ => panic!("index out of bounds"),
1888 }
1889 }
1890 }
1891
1892 impl IndexMut<usize> for Vec3A {
1893 #[inline]
index_mut(&mut self, index: usize) -> &mut Self::Output1894 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1895 match index {
1896 0 => &mut self.x,
1897 1 => &mut self.y,
1898 2 => &mut self.z,
1899 _ => panic!("index out of bounds"),
1900 }
1901 }
1902 }
1903
1904 impl fmt::Display for Vec3A {
fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result1905 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1906 if let Some(p) = f.precision() {
1907 write!(f, "[{:.*}, {:.*}, {:.*}]", p, self.x, p, self.y, p, self.z)
1908 } else {
1909 write!(f, "[{}, {}, {}]", self.x, self.y, self.z)
1910 }
1911 }
1912 }
1913
1914 impl fmt::Debug for Vec3A {
fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result1915 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1916 fmt.debug_tuple(stringify!(Vec3A))
1917 .field(&self.x)
1918 .field(&self.y)
1919 .field(&self.z)
1920 .finish()
1921 }
1922 }
1923
1924 impl From<[f32; 3]> for Vec3A {
1925 #[inline]
from(a: [f32; 3]) -> Self1926 fn from(a: [f32; 3]) -> Self {
1927 Self::new(a[0], a[1], a[2])
1928 }
1929 }
1930
1931 impl From<Vec3A> for [f32; 3] {
1932 #[inline]
from(v: Vec3A) -> Self1933 fn from(v: Vec3A) -> Self {
1934 [v.x, v.y, v.z]
1935 }
1936 }
1937
1938 impl From<(f32, f32, f32)> for Vec3A {
1939 #[inline]
from(t: (f32, f32, f32)) -> Self1940 fn from(t: (f32, f32, f32)) -> Self {
1941 Self::new(t.0, t.1, t.2)
1942 }
1943 }
1944
1945 impl From<Vec3A> for (f32, f32, f32) {
1946 #[inline]
from(v: Vec3A) -> Self1947 fn from(v: Vec3A) -> Self {
1948 (v.x, v.y, v.z)
1949 }
1950 }
1951
1952 impl From<Vec3> for Vec3A {
1953 #[inline]
from(v: Vec3) -> Self1954 fn from(v: Vec3) -> Self {
1955 Self::new(v.x, v.y, v.z)
1956 }
1957 }
1958
1959 impl From<Vec3A> for Vec3 {
1960 #[inline]
from(v: Vec3A) -> Self1961 fn from(v: Vec3A) -> Self {
1962 Self {
1963 x: v.x,
1964 y: v.y,
1965 z: v.z,
1966 }
1967 }
1968 }
1969
1970 impl From<(Vec2, f32)> for Vec3A {
1971 #[inline]
from((v, z): (Vec2, f32)) -> Self1972 fn from((v, z): (Vec2, f32)) -> Self {
1973 Self::new(v.x, v.y, z)
1974 }
1975 }
1976
1977 impl From<BVec3> for Vec3A {
1978 #[inline]
from(v: BVec3) -> Self1979 fn from(v: BVec3) -> Self {
1980 Self::new(f32::from(v.x), f32::from(v.y), f32::from(v.z))
1981 }
1982 }
1983
1984 impl From<BVec3A> for Vec3A {
1985 #[inline]
from(v: BVec3A) -> Self1986 fn from(v: BVec3A) -> Self {
1987 let bool_array: [bool; 3] = v.into();
1988 Self::new(
1989 f32::from(bool_array[0]),
1990 f32::from(bool_array[1]),
1991 f32::from(bool_array[2]),
1992 )
1993 }
1994 }
1995