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