1use crate::{f32::math, BVec3, BVec3A, FloatExt, Quat, Vec2, Vec3A, Vec4};
4
5use core::fmt;
6use core::iter::{Product, Sum};
7use core::{f32, ops::*};
8
9#[inline(always)]
11#[must_use]
12pub const fn vec3(x: f32, y: f32, z: f32) -> Vec3 {
13 Vec3::new(x, y, z)
14}
15
16#[derive(Clone, Copy, PartialEq)]
18#[cfg_attr(
19 all(feature = "bytemuck", not(target_arch = "spirv")),
20 derive(bytemuck::Pod, bytemuck::Zeroable)
21)]
22#[cfg_attr(not(target_arch = "spirv"), repr(C))]
23#[cfg_attr(target_arch = "spirv", repr(simd))]
24pub struct Vec3 {
25 pub x: f32,
26 pub y: f32,
27 pub z: f32,
28}
29
30impl Vec3 {
31 pub const ZERO: Self = Self::splat(0.0);
33
34 pub const ONE: Self = Self::splat(1.0);
36
37 pub const NEG_ONE: Self = Self::splat(-1.0);
39
40 pub const MIN: Self = Self::splat(f32::MIN);
42
43 pub const MAX: Self = Self::splat(f32::MAX);
45
46 pub const NAN: Self = Self::splat(f32::NAN);
48
49 pub const INFINITY: Self = Self::splat(f32::INFINITY);
51
52 pub const NEG_INFINITY: Self = Self::splat(f32::NEG_INFINITY);
54
55 pub const X: Self = Self::new(1.0, 0.0, 0.0);
57
58 pub const Y: Self = Self::new(0.0, 1.0, 0.0);
60
61 pub const Z: Self = Self::new(0.0, 0.0, 1.0);
63
64 pub const NEG_X: Self = Self::new(-1.0, 0.0, 0.0);
66
67 pub const NEG_Y: Self = Self::new(0.0, -1.0, 0.0);
69
70 pub const NEG_Z: Self = Self::new(0.0, 0.0, -1.0);
72
73 pub const AXES: [Self; 3] = [Self::X, Self::Y, Self::Z];
75
76 pub const USES_CORE_SIMD: bool = false;
78 pub const USES_NEON: bool = false;
80 pub const USES_SCALAR_MATH: bool = true;
82 pub const USES_SSE2: bool = false;
84 pub const USES_WASM32_SIMD: bool = false;
86
87 #[inline(always)]
89 #[must_use]
90 pub const fn new(x: f32, y: f32, z: f32) -> Self {
91 Self { x, y, z }
92 }
93
94 #[inline]
96 #[must_use]
97 pub const fn splat(v: f32) -> Self {
98 Self { x: v, y: v, z: v }
99 }
100
101 #[inline]
103 #[must_use]
104 pub fn map<F>(self, f: F) -> Self
105 where
106 F: Fn(f32) -> f32,
107 {
108 Self::new(f(self.x), f(self.y), f(self.z))
109 }
110
111 #[inline]
117 #[must_use]
118 pub fn select(mask: BVec3, if_true: Self, if_false: Self) -> Self {
119 Self {
120 x: if mask.test(0) { if_true.x } else { if_false.x },
121 y: if mask.test(1) { if_true.y } else { if_false.y },
122 z: if mask.test(2) { if_true.z } else { if_false.z },
123 }
124 }
125
126 #[inline]
128 #[must_use]
129 pub const fn from_array(a: [f32; 3]) -> Self {
130 Self::new(a[0], a[1], a[2])
131 }
132
133 #[inline]
135 #[must_use]
136 pub const fn to_array(&self) -> [f32; 3] {
137 [self.x, self.y, self.z]
138 }
139
140 #[inline]
146 #[must_use]
147 pub const fn from_slice(slice: &[f32]) -> Self {
148 assert!(slice.len() >= 3);
149 Self::new(slice[0], slice[1], slice[2])
150 }
151
152 #[inline]
158 pub fn write_to_slice(self, slice: &mut [f32]) {
159 slice[..3].copy_from_slice(&self.to_array());
160 }
161
162 #[allow(dead_code)]
164 #[inline]
165 #[must_use]
166 pub(crate) fn from_vec4(v: Vec4) -> Self {
167 Self {
168 x: v.x,
169 y: v.y,
170 z: v.z,
171 }
172 }
173
174 #[inline]
176 #[must_use]
177 pub fn extend(self, w: f32) -> Vec4 {
178 Vec4::new(self.x, self.y, self.z, w)
179 }
180
181 #[inline]
185 #[must_use]
186 pub fn truncate(self) -> Vec2 {
187 use crate::swizzles::Vec3Swizzles;
188 self.xy()
189 }
190
191 #[inline]
193 #[must_use]
194 pub fn to_vec3a(self) -> Vec3A {
195 Vec3A::from(self)
196 }
197
198 #[inline]
200 #[must_use]
201 pub fn with_x(mut self, x: f32) -> Self {
202 self.x = x;
203 self
204 }
205
206 #[inline]
208 #[must_use]
209 pub fn with_y(mut self, y: f32) -> Self {
210 self.y = y;
211 self
212 }
213
214 #[inline]
216 #[must_use]
217 pub fn with_z(mut self, z: f32) -> Self {
218 self.z = z;
219 self
220 }
221
222 #[inline]
224 #[must_use]
225 pub fn dot(self, rhs: Self) -> f32 {
226 (self.x * rhs.x) + (self.y * rhs.y) + (self.z * rhs.z)
227 }
228
229 #[inline]
231 #[must_use]
232 pub fn dot_into_vec(self, rhs: Self) -> Self {
233 Self::splat(self.dot(rhs))
234 }
235
236 #[inline]
238 #[must_use]
239 pub fn cross(self, rhs: Self) -> Self {
240 Self {
241 x: self.y * rhs.z - rhs.y * self.z,
242 y: self.z * rhs.x - rhs.z * self.x,
243 z: self.x * rhs.y - rhs.x * self.y,
244 }
245 }
246
247 #[inline]
254 #[must_use]
255 pub fn min(self, rhs: Self) -> Self {
256 Self {
257 x: if self.x < rhs.x { self.x } else { rhs.x },
258 y: if self.y < rhs.y { self.y } else { rhs.y },
259 z: if self.z < rhs.z { self.z } else { rhs.z },
260 }
261 }
262
263 #[inline]
270 #[must_use]
271 pub fn max(self, rhs: Self) -> Self {
272 Self {
273 x: if self.x > rhs.x { self.x } else { rhs.x },
274 y: if self.y > rhs.y { self.y } else { rhs.y },
275 z: if self.z > rhs.z { self.z } else { rhs.z },
276 }
277 }
278
279 #[inline]
290 #[must_use]
291 pub fn clamp(self, min: Self, max: Self) -> Self {
292 glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
293 self.max(min).min(max)
294 }
295
296 #[inline]
303 #[must_use]
304 pub fn min_element(self) -> f32 {
305 let min = |a, b| if a < b { a } else { b };
306 min(self.x, min(self.y, self.z))
307 }
308
309 #[inline]
316 #[must_use]
317 pub fn max_element(self) -> f32 {
318 let max = |a, b| if a > b { a } else { b };
319 max(self.x, max(self.y, self.z))
320 }
321
322 #[doc(alias = "argmin")]
324 #[inline]
325 #[must_use]
326 pub fn min_position(self) -> usize {
327 let mut min = self.x;
328 let mut index = 0;
329 if self.y < min {
330 min = self.y;
331 index = 1;
332 }
333 if self.z < min {
334 index = 2;
335 }
336 index
337 }
338
339 #[doc(alias = "argmax")]
341 #[inline]
342 #[must_use]
343 pub fn max_position(self) -> usize {
344 let mut max = self.x;
345 let mut index = 0;
346 if self.y > max {
347 max = self.y;
348 index = 1;
349 }
350 if self.z > max {
351 index = 2;
352 }
353 index
354 }
355
356 #[inline]
360 #[must_use]
361 pub fn element_sum(self) -> f32 {
362 self.x + self.y + self.z
363 }
364
365 #[inline]
369 #[must_use]
370 pub fn element_product(self) -> f32 {
371 self.x * self.y * self.z
372 }
373
374 #[inline]
380 #[must_use]
381 pub fn cmpeq(self, rhs: Self) -> BVec3 {
382 BVec3::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y), self.z.eq(&rhs.z))
383 }
384
385 #[inline]
391 #[must_use]
392 pub fn cmpne(self, rhs: Self) -> BVec3 {
393 BVec3::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y), self.z.ne(&rhs.z))
394 }
395
396 #[inline]
402 #[must_use]
403 pub fn cmpge(self, rhs: Self) -> BVec3 {
404 BVec3::new(self.x.ge(&rhs.x), self.y.ge(&rhs.y), self.z.ge(&rhs.z))
405 }
406
407 #[inline]
413 #[must_use]
414 pub fn cmpgt(self, rhs: Self) -> BVec3 {
415 BVec3::new(self.x.gt(&rhs.x), self.y.gt(&rhs.y), self.z.gt(&rhs.z))
416 }
417
418 #[inline]
424 #[must_use]
425 pub fn cmple(self, rhs: Self) -> BVec3 {
426 BVec3::new(self.x.le(&rhs.x), self.y.le(&rhs.y), self.z.le(&rhs.z))
427 }
428
429 #[inline]
435 #[must_use]
436 pub fn cmplt(self, rhs: Self) -> BVec3 {
437 BVec3::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y), self.z.lt(&rhs.z))
438 }
439
440 #[inline]
442 #[must_use]
443 pub fn abs(self) -> Self {
444 Self {
445 x: math::abs(self.x),
446 y: math::abs(self.y),
447 z: math::abs(self.z),
448 }
449 }
450
451 #[inline]
457 #[must_use]
458 pub fn signum(self) -> Self {
459 Self {
460 x: math::signum(self.x),
461 y: math::signum(self.y),
462 z: math::signum(self.z),
463 }
464 }
465
466 #[inline]
468 #[must_use]
469 pub fn copysign(self, rhs: Self) -> Self {
470 Self {
471 x: math::copysign(self.x, rhs.x),
472 y: math::copysign(self.y, rhs.y),
473 z: math::copysign(self.z, rhs.z),
474 }
475 }
476
477 #[inline]
485 #[must_use]
486 pub fn is_negative_bitmask(self) -> u32 {
487 (self.x.is_sign_negative() as u32)
488 | ((self.y.is_sign_negative() as u32) << 1)
489 | ((self.z.is_sign_negative() as u32) << 2)
490 }
491
492 #[inline]
495 #[must_use]
496 pub fn is_finite(self) -> bool {
497 self.x.is_finite() && self.y.is_finite() && self.z.is_finite()
498 }
499
500 #[inline]
504 #[must_use]
505 pub fn is_finite_mask(self) -> BVec3 {
506 BVec3::new(self.x.is_finite(), self.y.is_finite(), self.z.is_finite())
507 }
508
509 #[inline]
511 #[must_use]
512 pub fn is_nan(self) -> bool {
513 self.x.is_nan() || self.y.is_nan() || self.z.is_nan()
514 }
515
516 #[inline]
520 #[must_use]
521 pub fn is_nan_mask(self) -> BVec3 {
522 BVec3::new(self.x.is_nan(), self.y.is_nan(), self.z.is_nan())
523 }
524
525 #[doc(alias = "magnitude")]
527 #[inline]
528 #[must_use]
529 pub fn length(self) -> f32 {
530 math::sqrt(self.dot(self))
531 }
532
533 #[doc(alias = "magnitude2")]
537 #[inline]
538 #[must_use]
539 pub fn length_squared(self) -> f32 {
540 self.dot(self)
541 }
542
543 #[inline]
547 #[must_use]
548 pub fn length_recip(self) -> f32 {
549 self.length().recip()
550 }
551
552 #[inline]
554 #[must_use]
555 pub fn distance(self, rhs: Self) -> f32 {
556 (self - rhs).length()
557 }
558
559 #[inline]
561 #[must_use]
562 pub fn distance_squared(self, rhs: Self) -> f32 {
563 (self - rhs).length_squared()
564 }
565
566 #[inline]
568 #[must_use]
569 pub fn div_euclid(self, rhs: Self) -> Self {
570 Self::new(
571 math::div_euclid(self.x, rhs.x),
572 math::div_euclid(self.y, rhs.y),
573 math::div_euclid(self.z, rhs.z),
574 )
575 }
576
577 #[inline]
581 #[must_use]
582 pub fn rem_euclid(self, rhs: Self) -> Self {
583 Self::new(
584 math::rem_euclid(self.x, rhs.x),
585 math::rem_euclid(self.y, rhs.y),
586 math::rem_euclid(self.z, rhs.z),
587 )
588 }
589
590 #[inline]
600 #[must_use]
601 pub fn normalize(self) -> Self {
602 #[allow(clippy::let_and_return)]
603 let normalized = self.mul(self.length_recip());
604 glam_assert!(normalized.is_finite());
605 normalized
606 }
607
608 #[inline]
615 #[must_use]
616 pub fn try_normalize(self) -> Option<Self> {
617 let rcp = self.length_recip();
618 if rcp.is_finite() && rcp > 0.0 {
619 Some(self * rcp)
620 } else {
621 None
622 }
623 }
624
625 #[inline]
633 #[must_use]
634 pub fn normalize_or(self, fallback: Self) -> Self {
635 let rcp = self.length_recip();
636 if rcp.is_finite() && rcp > 0.0 {
637 self * rcp
638 } else {
639 fallback
640 }
641 }
642
643 #[inline]
650 #[must_use]
651 pub fn normalize_or_zero(self) -> Self {
652 self.normalize_or(Self::ZERO)
653 }
654
655 #[inline]
659 #[must_use]
660 pub fn normalize_and_length(self) -> (Self, f32) {
661 let length = self.length();
662 let rcp = 1.0 / length;
663 if rcp.is_finite() && rcp > 0.0 {
664 (self * rcp, length)
665 } else {
666 (Self::X, 0.0)
667 }
668 }
669
670 #[inline]
674 #[must_use]
675 pub fn is_normalized(self) -> bool {
676 math::abs(self.length_squared() - 1.0) <= 2e-4
677 }
678
679 #[inline]
687 #[must_use]
688 pub fn project_onto(self, rhs: Self) -> Self {
689 let other_len_sq_rcp = rhs.dot(rhs).recip();
690 glam_assert!(other_len_sq_rcp.is_finite());
691 rhs * self.dot(rhs) * other_len_sq_rcp
692 }
693
694 #[doc(alias("plane"))]
705 #[inline]
706 #[must_use]
707 pub fn reject_from(self, rhs: Self) -> Self {
708 self - self.project_onto(rhs)
709 }
710
711 #[inline]
719 #[must_use]
720 pub fn project_onto_normalized(self, rhs: Self) -> Self {
721 glam_assert!(rhs.is_normalized());
722 rhs * self.dot(rhs)
723 }
724
725 #[doc(alias("plane"))]
736 #[inline]
737 #[must_use]
738 pub fn reject_from_normalized(self, rhs: Self) -> Self {
739 self - self.project_onto_normalized(rhs)
740 }
741
742 #[inline]
745 #[must_use]
746 pub fn round(self) -> Self {
747 Self {
748 x: math::round(self.x),
749 y: math::round(self.y),
750 z: math::round(self.z),
751 }
752 }
753
754 #[inline]
757 #[must_use]
758 pub fn floor(self) -> Self {
759 Self {
760 x: math::floor(self.x),
761 y: math::floor(self.y),
762 z: math::floor(self.z),
763 }
764 }
765
766 #[inline]
769 #[must_use]
770 pub fn ceil(self) -> Self {
771 Self {
772 x: math::ceil(self.x),
773 y: math::ceil(self.y),
774 z: math::ceil(self.z),
775 }
776 }
777
778 #[inline]
781 #[must_use]
782 pub fn trunc(self) -> Self {
783 Self {
784 x: math::trunc(self.x),
785 y: math::trunc(self.y),
786 z: math::trunc(self.z),
787 }
788 }
789
790 #[inline]
797 #[must_use]
798 pub fn fract(self) -> Self {
799 self - self.trunc()
800 }
801
802 #[inline]
809 #[must_use]
810 pub fn fract_gl(self) -> Self {
811 self - self.floor()
812 }
813
814 #[inline]
817 #[must_use]
818 pub fn exp(self) -> Self {
819 Self::new(math::exp(self.x), math::exp(self.y), math::exp(self.z))
820 }
821
822 #[inline]
824 #[must_use]
825 pub fn powf(self, n: f32) -> Self {
826 Self::new(
827 math::powf(self.x, n),
828 math::powf(self.y, n),
829 math::powf(self.z, n),
830 )
831 }
832
833 #[inline]
835 #[must_use]
836 pub fn recip(self) -> Self {
837 Self {
838 x: 1.0 / self.x,
839 y: 1.0 / self.y,
840 z: 1.0 / self.z,
841 }
842 }
843
844 #[doc(alias = "mix")]
850 #[inline]
851 #[must_use]
852 pub fn lerp(self, rhs: Self, s: f32) -> Self {
853 self * (1.0 - s) + rhs * s
854 }
855
856 #[inline]
861 #[must_use]
862 pub fn move_towards(&self, rhs: Self, d: f32) -> Self {
863 let a = rhs - *self;
864 let len = a.length();
865 if len <= d || len <= 1e-4 {
866 return rhs;
867 }
868 *self + a / len * d
869 }
870
871 #[inline]
877 pub fn midpoint(self, rhs: Self) -> Self {
878 (self + rhs) * 0.5
879 }
880
881 #[inline]
891 #[must_use]
892 pub fn abs_diff_eq(self, rhs: Self, max_abs_diff: f32) -> bool {
893 self.sub(rhs).abs().cmple(Self::splat(max_abs_diff)).all()
894 }
895
896 #[inline]
902 #[must_use]
903 pub fn clamp_length(self, min: f32, max: f32) -> Self {
904 glam_assert!(0.0 <= min);
905 glam_assert!(min <= max);
906 let length_sq = self.length_squared();
907 if length_sq < min * min {
908 min * (self / math::sqrt(length_sq))
909 } else if length_sq > max * max {
910 max * (self / math::sqrt(length_sq))
911 } else {
912 self
913 }
914 }
915
916 #[inline]
922 #[must_use]
923 pub fn clamp_length_max(self, max: f32) -> Self {
924 glam_assert!(0.0 <= max);
925 let length_sq = self.length_squared();
926 if length_sq > max * max {
927 max * (self / math::sqrt(length_sq))
928 } else {
929 self
930 }
931 }
932
933 #[inline]
939 #[must_use]
940 pub fn clamp_length_min(self, min: f32) -> Self {
941 glam_assert!(0.0 <= min);
942 let length_sq = self.length_squared();
943 if length_sq < min * min {
944 min * (self / math::sqrt(length_sq))
945 } else {
946 self
947 }
948 }
949
950 #[inline]
958 #[must_use]
959 pub fn mul_add(self, a: Self, b: Self) -> Self {
960 Self::new(
961 math::mul_add(self.x, a.x, b.x),
962 math::mul_add(self.y, a.y, b.y),
963 math::mul_add(self.z, a.z, b.z),
964 )
965 }
966
967 #[inline]
976 #[must_use]
977 pub fn reflect(self, normal: Self) -> Self {
978 glam_assert!(normal.is_normalized());
979 self - 2.0 * self.dot(normal) * normal
980 }
981
982 #[inline]
992 #[must_use]
993 pub fn refract(self, normal: Self, eta: f32) -> Self {
994 glam_assert!(self.is_normalized());
995 glam_assert!(normal.is_normalized());
996 let n_dot_i = normal.dot(self);
997 let k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
998 if k >= 0.0 {
999 eta * self - (eta * n_dot_i + math::sqrt(k)) * normal
1000 } else {
1001 Self::ZERO
1002 }
1003 }
1004
1005 #[inline]
1009 #[must_use]
1010 pub fn angle_between(self, rhs: Self) -> f32 {
1011 math::acos_approx(
1012 self.dot(rhs)
1013 .div(math::sqrt(self.length_squared().mul(rhs.length_squared()))),
1014 )
1015 }
1016
1017 #[inline]
1023 #[must_use]
1024 pub fn rotate_towards(self, rhs: Self, max_angle: f32) -> Self {
1025 let angle_between = self.angle_between(rhs);
1026 let angle = max_angle.clamp(angle_between - core::f32::consts::PI, angle_between);
1028 let axis = self
1029 .cross(rhs)
1030 .try_normalize()
1031 .unwrap_or_else(|| self.any_orthogonal_vector().normalize());
1032 Quat::from_axis_angle(axis, angle) * self
1033 }
1034
1035 #[inline]
1042 #[must_use]
1043 pub fn any_orthogonal_vector(&self) -> Self {
1044 if math::abs(self.x) > math::abs(self.y) {
1046 Self::new(-self.z, 0.0, self.x) } else {
1048 Self::new(0.0, self.z, -self.y) }
1050 }
1051
1052 #[inline]
1060 #[must_use]
1061 pub fn any_orthonormal_vector(&self) -> Self {
1062 glam_assert!(self.is_normalized());
1063 let sign = math::signum(self.z);
1065 let a = -1.0 / (sign + self.z);
1066 let b = self.x * self.y * a;
1067 Self::new(b, sign + self.y * self.y * a, -self.y)
1068 }
1069
1070 #[inline]
1077 #[must_use]
1078 pub fn any_orthonormal_pair(&self) -> (Self, Self) {
1079 glam_assert!(self.is_normalized());
1080 let sign = math::signum(self.z);
1082 let a = -1.0 / (sign + self.z);
1083 let b = self.x * self.y * a;
1084 (
1085 Self::new(1.0 + sign * self.x * self.x * a, sign * b, -sign * self.x),
1086 Self::new(b, sign + self.y * self.y * a, -self.y),
1087 )
1088 }
1089
1090 #[inline]
1096 #[must_use]
1097 pub fn slerp(self, rhs: Self, s: f32) -> Self {
1098 let self_length = self.length();
1099 let rhs_length = rhs.length();
1100 let dot = self.dot(rhs) / (self_length * rhs_length);
1102 if math::abs(dot) < 1.0 - 3e-7 {
1104 let theta = math::acos_approx(dot);
1106 let sin_theta = math::sin(theta);
1108 let t1 = math::sin(theta * (1. - s));
1109 let t2 = math::sin(theta * s);
1110
1111 let result_length = self_length.lerp(rhs_length, s);
1113 return (self * (result_length / self_length) * t1
1115 + rhs * (result_length / rhs_length) * t2)
1116 * sin_theta.recip();
1117 }
1118 if dot < 0.0 {
1119 let axis = self.any_orthogonal_vector().normalize();
1123 let rotation = Quat::from_axis_angle(axis, core::f32::consts::PI * s);
1124 let result_length = self_length.lerp(rhs_length, s);
1126 rotation * self * (result_length / self_length)
1127 } else {
1128 self.lerp(rhs, s)
1130 }
1131 }
1132
1133 #[inline]
1135 #[must_use]
1136 pub fn as_dvec3(&self) -> crate::DVec3 {
1137 crate::DVec3::new(self.x as f64, self.y as f64, self.z as f64)
1138 }
1139
1140 #[inline]
1142 #[must_use]
1143 pub fn as_i8vec3(&self) -> crate::I8Vec3 {
1144 crate::I8Vec3::new(self.x as i8, self.y as i8, self.z as i8)
1145 }
1146
1147 #[inline]
1149 #[must_use]
1150 pub fn as_u8vec3(&self) -> crate::U8Vec3 {
1151 crate::U8Vec3::new(self.x as u8, self.y as u8, self.z as u8)
1152 }
1153
1154 #[inline]
1156 #[must_use]
1157 pub fn as_i16vec3(&self) -> crate::I16Vec3 {
1158 crate::I16Vec3::new(self.x as i16, self.y as i16, self.z as i16)
1159 }
1160
1161 #[inline]
1163 #[must_use]
1164 pub fn as_u16vec3(&self) -> crate::U16Vec3 {
1165 crate::U16Vec3::new(self.x as u16, self.y as u16, self.z as u16)
1166 }
1167
1168 #[inline]
1170 #[must_use]
1171 pub fn as_ivec3(&self) -> crate::IVec3 {
1172 crate::IVec3::new(self.x as i32, self.y as i32, self.z as i32)
1173 }
1174
1175 #[inline]
1177 #[must_use]
1178 pub fn as_uvec3(&self) -> crate::UVec3 {
1179 crate::UVec3::new(self.x as u32, self.y as u32, self.z as u32)
1180 }
1181
1182 #[inline]
1184 #[must_use]
1185 pub fn as_i64vec3(&self) -> crate::I64Vec3 {
1186 crate::I64Vec3::new(self.x as i64, self.y as i64, self.z as i64)
1187 }
1188
1189 #[inline]
1191 #[must_use]
1192 pub fn as_u64vec3(&self) -> crate::U64Vec3 {
1193 crate::U64Vec3::new(self.x as u64, self.y as u64, self.z as u64)
1194 }
1195
1196 #[inline]
1198 #[must_use]
1199 pub fn as_usizevec3(&self) -> crate::USizeVec3 {
1200 crate::USizeVec3::new(self.x as usize, self.y as usize, self.z as usize)
1201 }
1202}
1203
1204impl Default for Vec3 {
1205 #[inline(always)]
1206 fn default() -> Self {
1207 Self::ZERO
1208 }
1209}
1210
1211impl Div for Vec3 {
1212 type Output = Self;
1213 #[inline]
1214 fn div(self, rhs: Self) -> Self {
1215 Self {
1216 x: self.x.div(rhs.x),
1217 y: self.y.div(rhs.y),
1218 z: self.z.div(rhs.z),
1219 }
1220 }
1221}
1222
1223impl Div<&Self> for Vec3 {
1224 type Output = Self;
1225 #[inline]
1226 fn div(self, rhs: &Self) -> Self {
1227 self.div(*rhs)
1228 }
1229}
1230
1231impl Div<&Vec3> for &Vec3 {
1232 type Output = Vec3;
1233 #[inline]
1234 fn div(self, rhs: &Vec3) -> Vec3 {
1235 (*self).div(*rhs)
1236 }
1237}
1238
1239impl Div<Vec3> for &Vec3 {
1240 type Output = Vec3;
1241 #[inline]
1242 fn div(self, rhs: Vec3) -> Vec3 {
1243 (*self).div(rhs)
1244 }
1245}
1246
1247impl DivAssign for Vec3 {
1248 #[inline]
1249 fn div_assign(&mut self, rhs: Self) {
1250 self.x.div_assign(rhs.x);
1251 self.y.div_assign(rhs.y);
1252 self.z.div_assign(rhs.z);
1253 }
1254}
1255
1256impl DivAssign<&Self> for Vec3 {
1257 #[inline]
1258 fn div_assign(&mut self, rhs: &Self) {
1259 self.div_assign(*rhs);
1260 }
1261}
1262
1263impl Div<f32> for Vec3 {
1264 type Output = Self;
1265 #[inline]
1266 fn div(self, rhs: f32) -> Self {
1267 Self {
1268 x: self.x.div(rhs),
1269 y: self.y.div(rhs),
1270 z: self.z.div(rhs),
1271 }
1272 }
1273}
1274
1275impl Div<&f32> for Vec3 {
1276 type Output = Self;
1277 #[inline]
1278 fn div(self, rhs: &f32) -> Self {
1279 self.div(*rhs)
1280 }
1281}
1282
1283impl Div<&f32> for &Vec3 {
1284 type Output = Vec3;
1285 #[inline]
1286 fn div(self, rhs: &f32) -> Vec3 {
1287 (*self).div(*rhs)
1288 }
1289}
1290
1291impl Div<f32> for &Vec3 {
1292 type Output = Vec3;
1293 #[inline]
1294 fn div(self, rhs: f32) -> Vec3 {
1295 (*self).div(rhs)
1296 }
1297}
1298
1299impl DivAssign<f32> for Vec3 {
1300 #[inline]
1301 fn div_assign(&mut self, rhs: f32) {
1302 self.x.div_assign(rhs);
1303 self.y.div_assign(rhs);
1304 self.z.div_assign(rhs);
1305 }
1306}
1307
1308impl DivAssign<&f32> for Vec3 {
1309 #[inline]
1310 fn div_assign(&mut self, rhs: &f32) {
1311 self.div_assign(*rhs);
1312 }
1313}
1314
1315impl Div<Vec3> for f32 {
1316 type Output = Vec3;
1317 #[inline]
1318 fn div(self, rhs: Vec3) -> Vec3 {
1319 Vec3 {
1320 x: self.div(rhs.x),
1321 y: self.div(rhs.y),
1322 z: self.div(rhs.z),
1323 }
1324 }
1325}
1326
1327impl Div<&Vec3> for f32 {
1328 type Output = Vec3;
1329 #[inline]
1330 fn div(self, rhs: &Vec3) -> Vec3 {
1331 self.div(*rhs)
1332 }
1333}
1334
1335impl Div<&Vec3> for &f32 {
1336 type Output = Vec3;
1337 #[inline]
1338 fn div(self, rhs: &Vec3) -> Vec3 {
1339 (*self).div(*rhs)
1340 }
1341}
1342
1343impl Div<Vec3> for &f32 {
1344 type Output = Vec3;
1345 #[inline]
1346 fn div(self, rhs: Vec3) -> Vec3 {
1347 (*self).div(rhs)
1348 }
1349}
1350
1351impl Mul for Vec3 {
1352 type Output = Self;
1353 #[inline]
1354 fn mul(self, rhs: Self) -> Self {
1355 Self {
1356 x: self.x.mul(rhs.x),
1357 y: self.y.mul(rhs.y),
1358 z: self.z.mul(rhs.z),
1359 }
1360 }
1361}
1362
1363impl Mul<&Self> for Vec3 {
1364 type Output = Self;
1365 #[inline]
1366 fn mul(self, rhs: &Self) -> Self {
1367 self.mul(*rhs)
1368 }
1369}
1370
1371impl Mul<&Vec3> for &Vec3 {
1372 type Output = Vec3;
1373 #[inline]
1374 fn mul(self, rhs: &Vec3) -> Vec3 {
1375 (*self).mul(*rhs)
1376 }
1377}
1378
1379impl Mul<Vec3> for &Vec3 {
1380 type Output = Vec3;
1381 #[inline]
1382 fn mul(self, rhs: Vec3) -> Vec3 {
1383 (*self).mul(rhs)
1384 }
1385}
1386
1387impl MulAssign for Vec3 {
1388 #[inline]
1389 fn mul_assign(&mut self, rhs: Self) {
1390 self.x.mul_assign(rhs.x);
1391 self.y.mul_assign(rhs.y);
1392 self.z.mul_assign(rhs.z);
1393 }
1394}
1395
1396impl MulAssign<&Self> for Vec3 {
1397 #[inline]
1398 fn mul_assign(&mut self, rhs: &Self) {
1399 self.mul_assign(*rhs);
1400 }
1401}
1402
1403impl Mul<f32> for Vec3 {
1404 type Output = Self;
1405 #[inline]
1406 fn mul(self, rhs: f32) -> Self {
1407 Self {
1408 x: self.x.mul(rhs),
1409 y: self.y.mul(rhs),
1410 z: self.z.mul(rhs),
1411 }
1412 }
1413}
1414
1415impl Mul<&f32> for Vec3 {
1416 type Output = Self;
1417 #[inline]
1418 fn mul(self, rhs: &f32) -> Self {
1419 self.mul(*rhs)
1420 }
1421}
1422
1423impl Mul<&f32> for &Vec3 {
1424 type Output = Vec3;
1425 #[inline]
1426 fn mul(self, rhs: &f32) -> Vec3 {
1427 (*self).mul(*rhs)
1428 }
1429}
1430
1431impl Mul<f32> for &Vec3 {
1432 type Output = Vec3;
1433 #[inline]
1434 fn mul(self, rhs: f32) -> Vec3 {
1435 (*self).mul(rhs)
1436 }
1437}
1438
1439impl MulAssign<f32> for Vec3 {
1440 #[inline]
1441 fn mul_assign(&mut self, rhs: f32) {
1442 self.x.mul_assign(rhs);
1443 self.y.mul_assign(rhs);
1444 self.z.mul_assign(rhs);
1445 }
1446}
1447
1448impl MulAssign<&f32> for Vec3 {
1449 #[inline]
1450 fn mul_assign(&mut self, rhs: &f32) {
1451 self.mul_assign(*rhs);
1452 }
1453}
1454
1455impl Mul<Vec3> for f32 {
1456 type Output = Vec3;
1457 #[inline]
1458 fn mul(self, rhs: Vec3) -> Vec3 {
1459 Vec3 {
1460 x: self.mul(rhs.x),
1461 y: self.mul(rhs.y),
1462 z: self.mul(rhs.z),
1463 }
1464 }
1465}
1466
1467impl Mul<&Vec3> for f32 {
1468 type Output = Vec3;
1469 #[inline]
1470 fn mul(self, rhs: &Vec3) -> Vec3 {
1471 self.mul(*rhs)
1472 }
1473}
1474
1475impl Mul<&Vec3> for &f32 {
1476 type Output = Vec3;
1477 #[inline]
1478 fn mul(self, rhs: &Vec3) -> Vec3 {
1479 (*self).mul(*rhs)
1480 }
1481}
1482
1483impl Mul<Vec3> for &f32 {
1484 type Output = Vec3;
1485 #[inline]
1486 fn mul(self, rhs: Vec3) -> Vec3 {
1487 (*self).mul(rhs)
1488 }
1489}
1490
1491impl Add for Vec3 {
1492 type Output = Self;
1493 #[inline]
1494 fn add(self, rhs: Self) -> Self {
1495 Self {
1496 x: self.x.add(rhs.x),
1497 y: self.y.add(rhs.y),
1498 z: self.z.add(rhs.z),
1499 }
1500 }
1501}
1502
1503impl Add<&Self> for Vec3 {
1504 type Output = Self;
1505 #[inline]
1506 fn add(self, rhs: &Self) -> Self {
1507 self.add(*rhs)
1508 }
1509}
1510
1511impl Add<&Vec3> for &Vec3 {
1512 type Output = Vec3;
1513 #[inline]
1514 fn add(self, rhs: &Vec3) -> Vec3 {
1515 (*self).add(*rhs)
1516 }
1517}
1518
1519impl Add<Vec3> for &Vec3 {
1520 type Output = Vec3;
1521 #[inline]
1522 fn add(self, rhs: Vec3) -> Vec3 {
1523 (*self).add(rhs)
1524 }
1525}
1526
1527impl AddAssign for Vec3 {
1528 #[inline]
1529 fn add_assign(&mut self, rhs: Self) {
1530 self.x.add_assign(rhs.x);
1531 self.y.add_assign(rhs.y);
1532 self.z.add_assign(rhs.z);
1533 }
1534}
1535
1536impl AddAssign<&Self> for Vec3 {
1537 #[inline]
1538 fn add_assign(&mut self, rhs: &Self) {
1539 self.add_assign(*rhs);
1540 }
1541}
1542
1543impl Add<f32> for Vec3 {
1544 type Output = Self;
1545 #[inline]
1546 fn add(self, rhs: f32) -> Self {
1547 Self {
1548 x: self.x.add(rhs),
1549 y: self.y.add(rhs),
1550 z: self.z.add(rhs),
1551 }
1552 }
1553}
1554
1555impl Add<&f32> for Vec3 {
1556 type Output = Self;
1557 #[inline]
1558 fn add(self, rhs: &f32) -> Self {
1559 self.add(*rhs)
1560 }
1561}
1562
1563impl Add<&f32> for &Vec3 {
1564 type Output = Vec3;
1565 #[inline]
1566 fn add(self, rhs: &f32) -> Vec3 {
1567 (*self).add(*rhs)
1568 }
1569}
1570
1571impl Add<f32> for &Vec3 {
1572 type Output = Vec3;
1573 #[inline]
1574 fn add(self, rhs: f32) -> Vec3 {
1575 (*self).add(rhs)
1576 }
1577}
1578
1579impl AddAssign<f32> for Vec3 {
1580 #[inline]
1581 fn add_assign(&mut self, rhs: f32) {
1582 self.x.add_assign(rhs);
1583 self.y.add_assign(rhs);
1584 self.z.add_assign(rhs);
1585 }
1586}
1587
1588impl AddAssign<&f32> for Vec3 {
1589 #[inline]
1590 fn add_assign(&mut self, rhs: &f32) {
1591 self.add_assign(*rhs);
1592 }
1593}
1594
1595impl Add<Vec3> for f32 {
1596 type Output = Vec3;
1597 #[inline]
1598 fn add(self, rhs: Vec3) -> Vec3 {
1599 Vec3 {
1600 x: self.add(rhs.x),
1601 y: self.add(rhs.y),
1602 z: self.add(rhs.z),
1603 }
1604 }
1605}
1606
1607impl Add<&Vec3> for f32 {
1608 type Output = Vec3;
1609 #[inline]
1610 fn add(self, rhs: &Vec3) -> Vec3 {
1611 self.add(*rhs)
1612 }
1613}
1614
1615impl Add<&Vec3> for &f32 {
1616 type Output = Vec3;
1617 #[inline]
1618 fn add(self, rhs: &Vec3) -> Vec3 {
1619 (*self).add(*rhs)
1620 }
1621}
1622
1623impl Add<Vec3> for &f32 {
1624 type Output = Vec3;
1625 #[inline]
1626 fn add(self, rhs: Vec3) -> Vec3 {
1627 (*self).add(rhs)
1628 }
1629}
1630
1631impl Sub for Vec3 {
1632 type Output = Self;
1633 #[inline]
1634 fn sub(self, rhs: Self) -> Self {
1635 Self {
1636 x: self.x.sub(rhs.x),
1637 y: self.y.sub(rhs.y),
1638 z: self.z.sub(rhs.z),
1639 }
1640 }
1641}
1642
1643impl Sub<&Self> for Vec3 {
1644 type Output = Self;
1645 #[inline]
1646 fn sub(self, rhs: &Self) -> Self {
1647 self.sub(*rhs)
1648 }
1649}
1650
1651impl Sub<&Vec3> for &Vec3 {
1652 type Output = Vec3;
1653 #[inline]
1654 fn sub(self, rhs: &Vec3) -> Vec3 {
1655 (*self).sub(*rhs)
1656 }
1657}
1658
1659impl Sub<Vec3> for &Vec3 {
1660 type Output = Vec3;
1661 #[inline]
1662 fn sub(self, rhs: Vec3) -> Vec3 {
1663 (*self).sub(rhs)
1664 }
1665}
1666
1667impl SubAssign for Vec3 {
1668 #[inline]
1669 fn sub_assign(&mut self, rhs: Self) {
1670 self.x.sub_assign(rhs.x);
1671 self.y.sub_assign(rhs.y);
1672 self.z.sub_assign(rhs.z);
1673 }
1674}
1675
1676impl SubAssign<&Self> for Vec3 {
1677 #[inline]
1678 fn sub_assign(&mut self, rhs: &Self) {
1679 self.sub_assign(*rhs);
1680 }
1681}
1682
1683impl Sub<f32> for Vec3 {
1684 type Output = Self;
1685 #[inline]
1686 fn sub(self, rhs: f32) -> Self {
1687 Self {
1688 x: self.x.sub(rhs),
1689 y: self.y.sub(rhs),
1690 z: self.z.sub(rhs),
1691 }
1692 }
1693}
1694
1695impl Sub<&f32> for Vec3 {
1696 type Output = Self;
1697 #[inline]
1698 fn sub(self, rhs: &f32) -> Self {
1699 self.sub(*rhs)
1700 }
1701}
1702
1703impl Sub<&f32> for &Vec3 {
1704 type Output = Vec3;
1705 #[inline]
1706 fn sub(self, rhs: &f32) -> Vec3 {
1707 (*self).sub(*rhs)
1708 }
1709}
1710
1711impl Sub<f32> for &Vec3 {
1712 type Output = Vec3;
1713 #[inline]
1714 fn sub(self, rhs: f32) -> Vec3 {
1715 (*self).sub(rhs)
1716 }
1717}
1718
1719impl SubAssign<f32> for Vec3 {
1720 #[inline]
1721 fn sub_assign(&mut self, rhs: f32) {
1722 self.x.sub_assign(rhs);
1723 self.y.sub_assign(rhs);
1724 self.z.sub_assign(rhs);
1725 }
1726}
1727
1728impl SubAssign<&f32> for Vec3 {
1729 #[inline]
1730 fn sub_assign(&mut self, rhs: &f32) {
1731 self.sub_assign(*rhs);
1732 }
1733}
1734
1735impl Sub<Vec3> for f32 {
1736 type Output = Vec3;
1737 #[inline]
1738 fn sub(self, rhs: Vec3) -> Vec3 {
1739 Vec3 {
1740 x: self.sub(rhs.x),
1741 y: self.sub(rhs.y),
1742 z: self.sub(rhs.z),
1743 }
1744 }
1745}
1746
1747impl Sub<&Vec3> for f32 {
1748 type Output = Vec3;
1749 #[inline]
1750 fn sub(self, rhs: &Vec3) -> Vec3 {
1751 self.sub(*rhs)
1752 }
1753}
1754
1755impl Sub<&Vec3> for &f32 {
1756 type Output = Vec3;
1757 #[inline]
1758 fn sub(self, rhs: &Vec3) -> Vec3 {
1759 (*self).sub(*rhs)
1760 }
1761}
1762
1763impl Sub<Vec3> for &f32 {
1764 type Output = Vec3;
1765 #[inline]
1766 fn sub(self, rhs: Vec3) -> Vec3 {
1767 (*self).sub(rhs)
1768 }
1769}
1770
1771impl Rem for Vec3 {
1772 type Output = Self;
1773 #[inline]
1774 fn rem(self, rhs: Self) -> Self {
1775 Self {
1776 x: self.x.rem(rhs.x),
1777 y: self.y.rem(rhs.y),
1778 z: self.z.rem(rhs.z),
1779 }
1780 }
1781}
1782
1783impl Rem<&Self> for Vec3 {
1784 type Output = Self;
1785 #[inline]
1786 fn rem(self, rhs: &Self) -> Self {
1787 self.rem(*rhs)
1788 }
1789}
1790
1791impl Rem<&Vec3> for &Vec3 {
1792 type Output = Vec3;
1793 #[inline]
1794 fn rem(self, rhs: &Vec3) -> Vec3 {
1795 (*self).rem(*rhs)
1796 }
1797}
1798
1799impl Rem<Vec3> for &Vec3 {
1800 type Output = Vec3;
1801 #[inline]
1802 fn rem(self, rhs: Vec3) -> Vec3 {
1803 (*self).rem(rhs)
1804 }
1805}
1806
1807impl RemAssign for Vec3 {
1808 #[inline]
1809 fn rem_assign(&mut self, rhs: Self) {
1810 self.x.rem_assign(rhs.x);
1811 self.y.rem_assign(rhs.y);
1812 self.z.rem_assign(rhs.z);
1813 }
1814}
1815
1816impl RemAssign<&Self> for Vec3 {
1817 #[inline]
1818 fn rem_assign(&mut self, rhs: &Self) {
1819 self.rem_assign(*rhs);
1820 }
1821}
1822
1823impl Rem<f32> for Vec3 {
1824 type Output = Self;
1825 #[inline]
1826 fn rem(self, rhs: f32) -> Self {
1827 Self {
1828 x: self.x.rem(rhs),
1829 y: self.y.rem(rhs),
1830 z: self.z.rem(rhs),
1831 }
1832 }
1833}
1834
1835impl Rem<&f32> for Vec3 {
1836 type Output = Self;
1837 #[inline]
1838 fn rem(self, rhs: &f32) -> Self {
1839 self.rem(*rhs)
1840 }
1841}
1842
1843impl Rem<&f32> for &Vec3 {
1844 type Output = Vec3;
1845 #[inline]
1846 fn rem(self, rhs: &f32) -> Vec3 {
1847 (*self).rem(*rhs)
1848 }
1849}
1850
1851impl Rem<f32> for &Vec3 {
1852 type Output = Vec3;
1853 #[inline]
1854 fn rem(self, rhs: f32) -> Vec3 {
1855 (*self).rem(rhs)
1856 }
1857}
1858
1859impl RemAssign<f32> for Vec3 {
1860 #[inline]
1861 fn rem_assign(&mut self, rhs: f32) {
1862 self.x.rem_assign(rhs);
1863 self.y.rem_assign(rhs);
1864 self.z.rem_assign(rhs);
1865 }
1866}
1867
1868impl RemAssign<&f32> for Vec3 {
1869 #[inline]
1870 fn rem_assign(&mut self, rhs: &f32) {
1871 self.rem_assign(*rhs);
1872 }
1873}
1874
1875impl Rem<Vec3> for f32 {
1876 type Output = Vec3;
1877 #[inline]
1878 fn rem(self, rhs: Vec3) -> Vec3 {
1879 Vec3 {
1880 x: self.rem(rhs.x),
1881 y: self.rem(rhs.y),
1882 z: self.rem(rhs.z),
1883 }
1884 }
1885}
1886
1887impl Rem<&Vec3> for f32 {
1888 type Output = Vec3;
1889 #[inline]
1890 fn rem(self, rhs: &Vec3) -> Vec3 {
1891 self.rem(*rhs)
1892 }
1893}
1894
1895impl Rem<&Vec3> for &f32 {
1896 type Output = Vec3;
1897 #[inline]
1898 fn rem(self, rhs: &Vec3) -> Vec3 {
1899 (*self).rem(*rhs)
1900 }
1901}
1902
1903impl Rem<Vec3> for &f32 {
1904 type Output = Vec3;
1905 #[inline]
1906 fn rem(self, rhs: Vec3) -> Vec3 {
1907 (*self).rem(rhs)
1908 }
1909}
1910
1911#[cfg(not(target_arch = "spirv"))]
1912impl AsRef<[f32; 3]> for Vec3 {
1913 #[inline]
1914 fn as_ref(&self) -> &[f32; 3] {
1915 unsafe { &*(self as *const Self as *const [f32; 3]) }
1916 }
1917}
1918
1919#[cfg(not(target_arch = "spirv"))]
1920impl AsMut<[f32; 3]> for Vec3 {
1921 #[inline]
1922 fn as_mut(&mut self) -> &mut [f32; 3] {
1923 unsafe { &mut *(self as *mut Self as *mut [f32; 3]) }
1924 }
1925}
1926
1927impl Sum for Vec3 {
1928 #[inline]
1929 fn sum<I>(iter: I) -> Self
1930 where
1931 I: Iterator<Item = Self>,
1932 {
1933 iter.fold(Self::ZERO, Self::add)
1934 }
1935}
1936
1937impl<'a> Sum<&'a Self> for Vec3 {
1938 #[inline]
1939 fn sum<I>(iter: I) -> Self
1940 where
1941 I: Iterator<Item = &'a Self>,
1942 {
1943 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
1944 }
1945}
1946
1947impl Product for Vec3 {
1948 #[inline]
1949 fn product<I>(iter: I) -> Self
1950 where
1951 I: Iterator<Item = Self>,
1952 {
1953 iter.fold(Self::ONE, Self::mul)
1954 }
1955}
1956
1957impl<'a> Product<&'a Self> for Vec3 {
1958 #[inline]
1959 fn product<I>(iter: I) -> Self
1960 where
1961 I: Iterator<Item = &'a Self>,
1962 {
1963 iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
1964 }
1965}
1966
1967impl Neg for Vec3 {
1968 type Output = Self;
1969 #[inline]
1970 fn neg(self) -> Self {
1971 Self {
1972 x: self.x.neg(),
1973 y: self.y.neg(),
1974 z: self.z.neg(),
1975 }
1976 }
1977}
1978
1979impl Neg for &Vec3 {
1980 type Output = Vec3;
1981 #[inline]
1982 fn neg(self) -> Vec3 {
1983 (*self).neg()
1984 }
1985}
1986
1987impl Index<usize> for Vec3 {
1988 type Output = f32;
1989 #[inline]
1990 fn index(&self, index: usize) -> &Self::Output {
1991 match index {
1992 0 => &self.x,
1993 1 => &self.y,
1994 2 => &self.z,
1995 _ => panic!("index out of bounds"),
1996 }
1997 }
1998}
1999
2000impl IndexMut<usize> for Vec3 {
2001 #[inline]
2002 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
2003 match index {
2004 0 => &mut self.x,
2005 1 => &mut self.y,
2006 2 => &mut self.z,
2007 _ => panic!("index out of bounds"),
2008 }
2009 }
2010}
2011
2012impl fmt::Display for Vec3 {
2013 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2014 if let Some(p) = f.precision() {
2015 write!(f, "[{:.*}, {:.*}, {:.*}]", p, self.x, p, self.y, p, self.z)
2016 } else {
2017 write!(f, "[{}, {}, {}]", self.x, self.y, self.z)
2018 }
2019 }
2020}
2021
2022impl fmt::Debug for Vec3 {
2023 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
2024 fmt.debug_tuple(stringify!(Vec3))
2025 .field(&self.x)
2026 .field(&self.y)
2027 .field(&self.z)
2028 .finish()
2029 }
2030}
2031
2032impl From<[f32; 3]> for Vec3 {
2033 #[inline]
2034 fn from(a: [f32; 3]) -> Self {
2035 Self::new(a[0], a[1], a[2])
2036 }
2037}
2038
2039impl From<Vec3> for [f32; 3] {
2040 #[inline]
2041 fn from(v: Vec3) -> Self {
2042 [v.x, v.y, v.z]
2043 }
2044}
2045
2046impl From<(f32, f32, f32)> for Vec3 {
2047 #[inline]
2048 fn from(t: (f32, f32, f32)) -> Self {
2049 Self::new(t.0, t.1, t.2)
2050 }
2051}
2052
2053impl From<Vec3> for (f32, f32, f32) {
2054 #[inline]
2055 fn from(v: Vec3) -> Self {
2056 (v.x, v.y, v.z)
2057 }
2058}
2059
2060impl From<(Vec2, f32)> for Vec3 {
2061 #[inline]
2062 fn from((v, z): (Vec2, f32)) -> Self {
2063 Self::new(v.x, v.y, z)
2064 }
2065}
2066
2067impl From<BVec3> for Vec3 {
2068 #[inline]
2069 fn from(v: BVec3) -> Self {
2070 Self::new(f32::from(v.x), f32::from(v.y), f32::from(v.z))
2071 }
2072}
2073
2074impl From<BVec3A> for Vec3 {
2075 #[inline]
2076 fn from(v: BVec3A) -> Self {
2077 let bool_array: [bool; 3] = v.into();
2078 Self::new(
2079 f32::from(bool_array[0]),
2080 f32::from(bool_array[1]),
2081 f32::from(bool_array[2]),
2082 )
2083 }
2084}