1use crate::{f32::math, BVec3, BVec3A, FloatExt, Quat, Vec2, 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(not(target_arch = "spirv"), repr(C))]
19#[cfg_attr(target_arch = "spirv", repr(simd))]
20pub struct Vec3 {
21 pub x: f32,
22 pub y: f32,
23 pub z: f32,
24}
25
26impl Vec3 {
27 pub const ZERO: Self = Self::splat(0.0);
29
30 pub const ONE: Self = Self::splat(1.0);
32
33 pub const NEG_ONE: Self = Self::splat(-1.0);
35
36 pub const MIN: Self = Self::splat(f32::MIN);
38
39 pub const MAX: Self = Self::splat(f32::MAX);
41
42 pub const NAN: Self = Self::splat(f32::NAN);
44
45 pub const INFINITY: Self = Self::splat(f32::INFINITY);
47
48 pub const NEG_INFINITY: Self = Self::splat(f32::NEG_INFINITY);
50
51 pub const X: Self = Self::new(1.0, 0.0, 0.0);
53
54 pub const Y: Self = Self::new(0.0, 1.0, 0.0);
56
57 pub const Z: Self = Self::new(0.0, 0.0, 1.0);
59
60 pub const NEG_X: Self = Self::new(-1.0, 0.0, 0.0);
62
63 pub const NEG_Y: Self = Self::new(0.0, -1.0, 0.0);
65
66 pub const NEG_Z: Self = Self::new(0.0, 0.0, -1.0);
68
69 pub const AXES: [Self; 3] = [Self::X, Self::Y, Self::Z];
71
72 pub const USES_CORE_SIMD: bool = false;
74 pub const USES_NEON: bool = false;
76 pub const USES_SCALAR_MATH: bool = true;
78 pub const USES_SSE2: bool = false;
80 pub const USES_WASM32_SIMD: bool = false;
82
83 #[inline(always)]
85 #[must_use]
86 pub const fn new(x: f32, y: f32, z: f32) -> Self {
87 Self { x, y, z }
88 }
89
90 #[inline]
92 #[must_use]
93 pub const fn splat(v: f32) -> Self {
94 Self { x: v, y: v, z: v }
95 }
96
97 #[inline]
99 #[must_use]
100 pub fn map<F>(self, f: F) -> Self
101 where
102 F: Fn(f32) -> f32,
103 {
104 Self::new(f(self.x), f(self.y), f(self.z))
105 }
106
107 #[inline]
113 #[must_use]
114 pub fn select(mask: BVec3, if_true: Self, if_false: Self) -> Self {
115 Self {
116 x: if mask.test(0) { if_true.x } else { if_false.x },
117 y: if mask.test(1) { if_true.y } else { if_false.y },
118 z: if mask.test(2) { if_true.z } else { if_false.z },
119 }
120 }
121
122 #[inline]
124 #[must_use]
125 pub const fn from_array(a: [f32; 3]) -> Self {
126 Self::new(a[0], a[1], a[2])
127 }
128
129 #[inline]
131 #[must_use]
132 pub const fn to_array(&self) -> [f32; 3] {
133 [self.x, self.y, self.z]
134 }
135
136 #[inline]
142 #[must_use]
143 pub const fn from_slice(slice: &[f32]) -> Self {
144 assert!(slice.len() >= 3);
145 Self::new(slice[0], slice[1], slice[2])
146 }
147
148 #[inline]
154 pub fn write_to_slice(self, slice: &mut [f32]) {
155 slice[..3].copy_from_slice(&self.to_array());
156 }
157
158 #[allow(dead_code)]
160 #[inline]
161 #[must_use]
162 pub(crate) fn from_vec4(v: Vec4) -> Self {
163 Self {
164 x: v.x,
165 y: v.y,
166 z: v.z,
167 }
168 }
169
170 #[inline]
172 #[must_use]
173 pub fn extend(self, w: f32) -> Vec4 {
174 Vec4::new(self.x, self.y, self.z, w)
175 }
176
177 #[inline]
181 #[must_use]
182 pub fn truncate(self) -> Vec2 {
183 use crate::swizzles::Vec3Swizzles;
184 self.xy()
185 }
186
187 #[inline]
189 #[must_use]
190 pub fn with_x(mut self, x: f32) -> Self {
191 self.x = x;
192 self
193 }
194
195 #[inline]
197 #[must_use]
198 pub fn with_y(mut self, y: f32) -> Self {
199 self.y = y;
200 self
201 }
202
203 #[inline]
205 #[must_use]
206 pub fn with_z(mut self, z: f32) -> Self {
207 self.z = z;
208 self
209 }
210
211 #[inline]
213 #[must_use]
214 pub fn dot(self, rhs: Self) -> f32 {
215 (self.x * rhs.x) + (self.y * rhs.y) + (self.z * rhs.z)
216 }
217
218 #[inline]
220 #[must_use]
221 pub fn dot_into_vec(self, rhs: Self) -> Self {
222 Self::splat(self.dot(rhs))
223 }
224
225 #[inline]
227 #[must_use]
228 pub fn cross(self, rhs: Self) -> Self {
229 Self {
230 x: self.y * rhs.z - rhs.y * self.z,
231 y: self.z * rhs.x - rhs.z * self.x,
232 z: self.x * rhs.y - rhs.x * self.y,
233 }
234 }
235
236 #[inline]
243 #[must_use]
244 pub fn min(self, rhs: Self) -> Self {
245 Self {
246 x: if self.x < rhs.x { self.x } else { rhs.x },
247 y: if self.y < rhs.y { self.y } else { rhs.y },
248 z: if self.z < rhs.z { self.z } else { rhs.z },
249 }
250 }
251
252 #[inline]
259 #[must_use]
260 pub fn max(self, rhs: Self) -> Self {
261 Self {
262 x: if self.x > rhs.x { self.x } else { rhs.x },
263 y: if self.y > rhs.y { self.y } else { rhs.y },
264 z: if self.z > rhs.z { self.z } else { rhs.z },
265 }
266 }
267
268 #[inline]
279 #[must_use]
280 pub fn clamp(self, min: Self, max: Self) -> Self {
281 glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
282 self.max(min).min(max)
283 }
284
285 #[inline]
292 #[must_use]
293 pub fn min_element(self) -> f32 {
294 let min = |a, b| if a < b { a } else { b };
295 min(self.x, min(self.y, self.z))
296 }
297
298 #[inline]
305 #[must_use]
306 pub fn max_element(self) -> f32 {
307 let max = |a, b| if a > b { a } else { b };
308 max(self.x, max(self.y, self.z))
309 }
310
311 #[doc(alias = "argmin")]
313 #[inline]
314 #[must_use]
315 pub fn min_position(self) -> usize {
316 let mut min = self.x;
317 let mut index = 0;
318 if self.y < min {
319 min = self.y;
320 index = 1;
321 }
322 if self.z < min {
323 index = 2;
324 }
325 index
326 }
327
328 #[doc(alias = "argmax")]
330 #[inline]
331 #[must_use]
332 pub fn max_position(self) -> usize {
333 let mut max = self.x;
334 let mut index = 0;
335 if self.y > max {
336 max = self.y;
337 index = 1;
338 }
339 if self.z > max {
340 index = 2;
341 }
342 index
343 }
344
345 #[inline]
349 #[must_use]
350 pub fn element_sum(self) -> f32 {
351 self.x + self.y + self.z
352 }
353
354 #[inline]
358 #[must_use]
359 pub fn element_product(self) -> f32 {
360 self.x * self.y * self.z
361 }
362
363 #[inline]
369 #[must_use]
370 pub fn cmpeq(self, rhs: Self) -> BVec3 {
371 BVec3::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y), self.z.eq(&rhs.z))
372 }
373
374 #[inline]
380 #[must_use]
381 pub fn cmpne(self, rhs: Self) -> BVec3 {
382 BVec3::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y), self.z.ne(&rhs.z))
383 }
384
385 #[inline]
391 #[must_use]
392 pub fn cmpge(self, rhs: Self) -> BVec3 {
393 BVec3::new(self.x.ge(&rhs.x), self.y.ge(&rhs.y), self.z.ge(&rhs.z))
394 }
395
396 #[inline]
402 #[must_use]
403 pub fn cmpgt(self, rhs: Self) -> BVec3 {
404 BVec3::new(self.x.gt(&rhs.x), self.y.gt(&rhs.y), self.z.gt(&rhs.z))
405 }
406
407 #[inline]
413 #[must_use]
414 pub fn cmple(self, rhs: Self) -> BVec3 {
415 BVec3::new(self.x.le(&rhs.x), self.y.le(&rhs.y), self.z.le(&rhs.z))
416 }
417
418 #[inline]
424 #[must_use]
425 pub fn cmplt(self, rhs: Self) -> BVec3 {
426 BVec3::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y), self.z.lt(&rhs.z))
427 }
428
429 #[inline]
431 #[must_use]
432 pub fn abs(self) -> Self {
433 Self {
434 x: math::abs(self.x),
435 y: math::abs(self.y),
436 z: math::abs(self.z),
437 }
438 }
439
440 #[inline]
446 #[must_use]
447 pub fn signum(self) -> Self {
448 Self {
449 x: math::signum(self.x),
450 y: math::signum(self.y),
451 z: math::signum(self.z),
452 }
453 }
454
455 #[inline]
457 #[must_use]
458 pub fn copysign(self, rhs: Self) -> Self {
459 Self {
460 x: math::copysign(self.x, rhs.x),
461 y: math::copysign(self.y, rhs.y),
462 z: math::copysign(self.z, rhs.z),
463 }
464 }
465
466 #[inline]
474 #[must_use]
475 pub fn is_negative_bitmask(self) -> u32 {
476 (self.x.is_sign_negative() as u32)
477 | ((self.y.is_sign_negative() as u32) << 1)
478 | ((self.z.is_sign_negative() as u32) << 2)
479 }
480
481 #[inline]
484 #[must_use]
485 pub fn is_finite(self) -> bool {
486 self.x.is_finite() && self.y.is_finite() && self.z.is_finite()
487 }
488
489 pub fn is_finite_mask(self) -> BVec3 {
493 BVec3::new(self.x.is_finite(), self.y.is_finite(), self.z.is_finite())
494 }
495
496 #[inline]
498 #[must_use]
499 pub fn is_nan(self) -> bool {
500 self.x.is_nan() || self.y.is_nan() || self.z.is_nan()
501 }
502
503 #[inline]
507 #[must_use]
508 pub fn is_nan_mask(self) -> BVec3 {
509 BVec3::new(self.x.is_nan(), self.y.is_nan(), self.z.is_nan())
510 }
511
512 #[doc(alias = "magnitude")]
514 #[inline]
515 #[must_use]
516 pub fn length(self) -> f32 {
517 math::sqrt(self.dot(self))
518 }
519
520 #[doc(alias = "magnitude2")]
524 #[inline]
525 #[must_use]
526 pub fn length_squared(self) -> f32 {
527 self.dot(self)
528 }
529
530 #[inline]
534 #[must_use]
535 pub fn length_recip(self) -> f32 {
536 self.length().recip()
537 }
538
539 #[inline]
541 #[must_use]
542 pub fn distance(self, rhs: Self) -> f32 {
543 (self - rhs).length()
544 }
545
546 #[inline]
548 #[must_use]
549 pub fn distance_squared(self, rhs: Self) -> f32 {
550 (self - rhs).length_squared()
551 }
552
553 #[inline]
555 #[must_use]
556 pub fn div_euclid(self, rhs: Self) -> Self {
557 Self::new(
558 math::div_euclid(self.x, rhs.x),
559 math::div_euclid(self.y, rhs.y),
560 math::div_euclid(self.z, rhs.z),
561 )
562 }
563
564 #[inline]
568 #[must_use]
569 pub fn rem_euclid(self, rhs: Self) -> Self {
570 Self::new(
571 math::rem_euclid(self.x, rhs.x),
572 math::rem_euclid(self.y, rhs.y),
573 math::rem_euclid(self.z, rhs.z),
574 )
575 }
576
577 #[inline]
587 #[must_use]
588 pub fn normalize(self) -> Self {
589 #[allow(clippy::let_and_return)]
590 let normalized = self.mul(self.length_recip());
591 glam_assert!(normalized.is_finite());
592 normalized
593 }
594
595 #[inline]
602 #[must_use]
603 pub fn try_normalize(self) -> Option<Self> {
604 let rcp = self.length_recip();
605 if rcp.is_finite() && rcp > 0.0 {
606 Some(self * rcp)
607 } else {
608 None
609 }
610 }
611
612 #[inline]
620 #[must_use]
621 pub fn normalize_or(self, fallback: Self) -> Self {
622 let rcp = self.length_recip();
623 if rcp.is_finite() && rcp > 0.0 {
624 self * rcp
625 } else {
626 fallback
627 }
628 }
629
630 #[inline]
637 #[must_use]
638 pub fn normalize_or_zero(self) -> Self {
639 self.normalize_or(Self::ZERO)
640 }
641
642 #[inline]
646 #[must_use]
647 pub fn normalize_and_length(self) -> (Self, f32) {
648 let length = self.length();
649 let rcp = 1.0 / length;
650 if rcp.is_finite() && rcp > 0.0 {
651 (self * rcp, length)
652 } else {
653 (Self::X, 0.0)
654 }
655 }
656
657 #[inline]
661 #[must_use]
662 pub fn is_normalized(self) -> bool {
663 math::abs(self.length_squared() - 1.0) <= 2e-4
664 }
665
666 #[inline]
674 #[must_use]
675 pub fn project_onto(self, rhs: Self) -> Self {
676 let other_len_sq_rcp = rhs.dot(rhs).recip();
677 glam_assert!(other_len_sq_rcp.is_finite());
678 rhs * self.dot(rhs) * other_len_sq_rcp
679 }
680
681 #[doc(alias("plane"))]
692 #[inline]
693 #[must_use]
694 pub fn reject_from(self, rhs: Self) -> Self {
695 self - self.project_onto(rhs)
696 }
697
698 #[inline]
706 #[must_use]
707 pub fn project_onto_normalized(self, rhs: Self) -> Self {
708 glam_assert!(rhs.is_normalized());
709 rhs * self.dot(rhs)
710 }
711
712 #[doc(alias("plane"))]
723 #[inline]
724 #[must_use]
725 pub fn reject_from_normalized(self, rhs: Self) -> Self {
726 self - self.project_onto_normalized(rhs)
727 }
728
729 #[inline]
732 #[must_use]
733 pub fn round(self) -> Self {
734 Self {
735 x: math::round(self.x),
736 y: math::round(self.y),
737 z: math::round(self.z),
738 }
739 }
740
741 #[inline]
744 #[must_use]
745 pub fn floor(self) -> Self {
746 Self {
747 x: math::floor(self.x),
748 y: math::floor(self.y),
749 z: math::floor(self.z),
750 }
751 }
752
753 #[inline]
756 #[must_use]
757 pub fn ceil(self) -> Self {
758 Self {
759 x: math::ceil(self.x),
760 y: math::ceil(self.y),
761 z: math::ceil(self.z),
762 }
763 }
764
765 #[inline]
768 #[must_use]
769 pub fn trunc(self) -> Self {
770 Self {
771 x: math::trunc(self.x),
772 y: math::trunc(self.y),
773 z: math::trunc(self.z),
774 }
775 }
776
777 #[inline]
784 #[must_use]
785 pub fn fract(self) -> Self {
786 self - self.trunc()
787 }
788
789 #[inline]
796 #[must_use]
797 pub fn fract_gl(self) -> Self {
798 self - self.floor()
799 }
800
801 #[inline]
804 #[must_use]
805 pub fn exp(self) -> Self {
806 Self::new(math::exp(self.x), math::exp(self.y), math::exp(self.z))
807 }
808
809 #[inline]
811 #[must_use]
812 pub fn powf(self, n: f32) -> Self {
813 Self::new(
814 math::powf(self.x, n),
815 math::powf(self.y, n),
816 math::powf(self.z, n),
817 )
818 }
819
820 #[inline]
822 #[must_use]
823 pub fn recip(self) -> Self {
824 Self {
825 x: 1.0 / self.x,
826 y: 1.0 / self.y,
827 z: 1.0 / self.z,
828 }
829 }
830
831 #[doc(alias = "mix")]
837 #[inline]
838 #[must_use]
839 pub fn lerp(self, rhs: Self, s: f32) -> Self {
840 self * (1.0 - s) + rhs * s
841 }
842
843 #[inline]
848 #[must_use]
849 pub fn move_towards(&self, rhs: Self, d: f32) -> Self {
850 let a = rhs - *self;
851 let len = a.length();
852 if len <= d || len <= 1e-4 {
853 return rhs;
854 }
855 *self + a / len * d
856 }
857
858 #[inline]
864 pub fn midpoint(self, rhs: Self) -> Self {
865 (self + rhs) * 0.5
866 }
867
868 #[inline]
878 #[must_use]
879 pub fn abs_diff_eq(self, rhs: Self, max_abs_diff: f32) -> bool {
880 self.sub(rhs).abs().cmple(Self::splat(max_abs_diff)).all()
881 }
882
883 #[inline]
889 #[must_use]
890 pub fn clamp_length(self, min: f32, max: f32) -> Self {
891 glam_assert!(0.0 <= min);
892 glam_assert!(min <= max);
893 let length_sq = self.length_squared();
894 if length_sq < min * min {
895 min * (self / math::sqrt(length_sq))
896 } else if length_sq > max * max {
897 max * (self / math::sqrt(length_sq))
898 } else {
899 self
900 }
901 }
902
903 #[inline]
909 #[must_use]
910 pub fn clamp_length_max(self, max: f32) -> Self {
911 glam_assert!(0.0 <= max);
912 let length_sq = self.length_squared();
913 if length_sq > max * max {
914 max * (self / math::sqrt(length_sq))
915 } else {
916 self
917 }
918 }
919
920 #[inline]
926 #[must_use]
927 pub fn clamp_length_min(self, min: f32) -> Self {
928 glam_assert!(0.0 <= min);
929 let length_sq = self.length_squared();
930 if length_sq < min * min {
931 min * (self / math::sqrt(length_sq))
932 } else {
933 self
934 }
935 }
936
937 #[inline]
945 #[must_use]
946 pub fn mul_add(self, a: Self, b: Self) -> Self {
947 Self::new(
948 math::mul_add(self.x, a.x, b.x),
949 math::mul_add(self.y, a.y, b.y),
950 math::mul_add(self.z, a.z, b.z),
951 )
952 }
953
954 #[inline]
963 #[must_use]
964 pub fn reflect(self, normal: Self) -> Self {
965 glam_assert!(normal.is_normalized());
966 self - 2.0 * self.dot(normal) * normal
967 }
968
969 #[inline]
979 #[must_use]
980 pub fn refract(self, normal: Self, eta: f32) -> Self {
981 glam_assert!(self.is_normalized());
982 glam_assert!(normal.is_normalized());
983 let n_dot_i = normal.dot(self);
984 let k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
985 if k >= 0.0 {
986 eta * self - (eta * n_dot_i + math::sqrt(k)) * normal
987 } else {
988 Self::ZERO
989 }
990 }
991
992 #[inline]
996 #[must_use]
997 pub fn angle_between(self, rhs: Self) -> f32 {
998 math::acos_approx(
999 self.dot(rhs)
1000 .div(math::sqrt(self.length_squared().mul(rhs.length_squared()))),
1001 )
1002 }
1003
1004 #[inline]
1010 #[must_use]
1011 pub fn rotate_towards(self, rhs: Self, max_angle: f32) -> Self {
1012 let angle_between = self.angle_between(rhs);
1013 let angle = max_angle.clamp(angle_between - core::f32::consts::PI, angle_between);
1015 let axis = self
1016 .cross(rhs)
1017 .try_normalize()
1018 .unwrap_or_else(|| self.any_orthogonal_vector().normalize());
1019 Quat::from_axis_angle(axis, angle) * self
1020 }
1021
1022 #[inline]
1029 #[must_use]
1030 pub fn any_orthogonal_vector(&self) -> Self {
1031 if math::abs(self.x) > math::abs(self.y) {
1033 Self::new(-self.z, 0.0, self.x) } else {
1035 Self::new(0.0, self.z, -self.y) }
1037 }
1038
1039 #[inline]
1047 #[must_use]
1048 pub fn any_orthonormal_vector(&self) -> Self {
1049 glam_assert!(self.is_normalized());
1050 let sign = math::signum(self.z);
1052 let a = -1.0 / (sign + self.z);
1053 let b = self.x * self.y * a;
1054 Self::new(b, sign + self.y * self.y * a, -self.y)
1055 }
1056
1057 #[inline]
1064 #[must_use]
1065 pub fn any_orthonormal_pair(&self) -> (Self, Self) {
1066 glam_assert!(self.is_normalized());
1067 let sign = math::signum(self.z);
1069 let a = -1.0 / (sign + self.z);
1070 let b = self.x * self.y * a;
1071 (
1072 Self::new(1.0 + sign * self.x * self.x * a, sign * b, -sign * self.x),
1073 Self::new(b, sign + self.y * self.y * a, -self.y),
1074 )
1075 }
1076
1077 #[inline]
1083 #[must_use]
1084 pub fn slerp(self, rhs: Self, s: f32) -> Self {
1085 let self_length = self.length();
1086 let rhs_length = rhs.length();
1087 let dot = self.dot(rhs) / (self_length * rhs_length);
1089 if math::abs(dot) < 1.0 - 3e-7 {
1091 let theta = math::acos_approx(dot);
1093 let sin_theta = math::sin(theta);
1095 let t1 = math::sin(theta * (1. - s));
1096 let t2 = math::sin(theta * s);
1097
1098 let result_length = self_length.lerp(rhs_length, s);
1100 return (self * (result_length / self_length) * t1
1102 + rhs * (result_length / rhs_length) * t2)
1103 * sin_theta.recip();
1104 }
1105 if dot < 0.0 {
1106 let axis = self.any_orthogonal_vector().normalize();
1110 let rotation = Quat::from_axis_angle(axis, core::f32::consts::PI * s);
1111 let result_length = self_length.lerp(rhs_length, s);
1113 rotation * self * (result_length / self_length)
1114 } else {
1115 self.lerp(rhs, s)
1117 }
1118 }
1119
1120 #[inline]
1122 #[must_use]
1123 pub fn as_dvec3(&self) -> crate::DVec3 {
1124 crate::DVec3::new(self.x as f64, self.y as f64, self.z as f64)
1125 }
1126
1127 #[inline]
1129 #[must_use]
1130 pub fn as_i8vec3(&self) -> crate::I8Vec3 {
1131 crate::I8Vec3::new(self.x as i8, self.y as i8, self.z as i8)
1132 }
1133
1134 #[inline]
1136 #[must_use]
1137 pub fn as_u8vec3(&self) -> crate::U8Vec3 {
1138 crate::U8Vec3::new(self.x as u8, self.y as u8, self.z as u8)
1139 }
1140
1141 #[inline]
1143 #[must_use]
1144 pub fn as_i16vec3(&self) -> crate::I16Vec3 {
1145 crate::I16Vec3::new(self.x as i16, self.y as i16, self.z as i16)
1146 }
1147
1148 #[inline]
1150 #[must_use]
1151 pub fn as_u16vec3(&self) -> crate::U16Vec3 {
1152 crate::U16Vec3::new(self.x as u16, self.y as u16, self.z as u16)
1153 }
1154
1155 #[inline]
1157 #[must_use]
1158 pub fn as_ivec3(&self) -> crate::IVec3 {
1159 crate::IVec3::new(self.x as i32, self.y as i32, self.z as i32)
1160 }
1161
1162 #[inline]
1164 #[must_use]
1165 pub fn as_uvec3(&self) -> crate::UVec3 {
1166 crate::UVec3::new(self.x as u32, self.y as u32, self.z as u32)
1167 }
1168
1169 #[inline]
1171 #[must_use]
1172 pub fn as_i64vec3(&self) -> crate::I64Vec3 {
1173 crate::I64Vec3::new(self.x as i64, self.y as i64, self.z as i64)
1174 }
1175
1176 #[inline]
1178 #[must_use]
1179 pub fn as_u64vec3(&self) -> crate::U64Vec3 {
1180 crate::U64Vec3::new(self.x as u64, self.y as u64, self.z as u64)
1181 }
1182
1183 #[inline]
1185 #[must_use]
1186 pub fn as_usizevec3(&self) -> crate::USizeVec3 {
1187 crate::USizeVec3::new(self.x as usize, self.y as usize, self.z as usize)
1188 }
1189}
1190
1191impl Default for Vec3 {
1192 #[inline(always)]
1193 fn default() -> Self {
1194 Self::ZERO
1195 }
1196}
1197
1198impl Div<Vec3> for Vec3 {
1199 type Output = Self;
1200 #[inline]
1201 fn div(self, rhs: Self) -> Self {
1202 Self {
1203 x: self.x.div(rhs.x),
1204 y: self.y.div(rhs.y),
1205 z: self.z.div(rhs.z),
1206 }
1207 }
1208}
1209
1210impl Div<&Vec3> for Vec3 {
1211 type Output = Vec3;
1212 #[inline]
1213 fn div(self, rhs: &Vec3) -> Vec3 {
1214 self.div(*rhs)
1215 }
1216}
1217
1218impl Div<&Vec3> for &Vec3 {
1219 type Output = Vec3;
1220 #[inline]
1221 fn div(self, rhs: &Vec3) -> Vec3 {
1222 (*self).div(*rhs)
1223 }
1224}
1225
1226impl Div<Vec3> for &Vec3 {
1227 type Output = Vec3;
1228 #[inline]
1229 fn div(self, rhs: Vec3) -> Vec3 {
1230 (*self).div(rhs)
1231 }
1232}
1233
1234impl DivAssign<Vec3> for Vec3 {
1235 #[inline]
1236 fn div_assign(&mut self, rhs: Self) {
1237 self.x.div_assign(rhs.x);
1238 self.y.div_assign(rhs.y);
1239 self.z.div_assign(rhs.z);
1240 }
1241}
1242
1243impl DivAssign<&Vec3> for Vec3 {
1244 #[inline]
1245 fn div_assign(&mut self, rhs: &Vec3) {
1246 self.div_assign(*rhs)
1247 }
1248}
1249
1250impl Div<f32> for Vec3 {
1251 type Output = Self;
1252 #[inline]
1253 fn div(self, rhs: f32) -> Self {
1254 Self {
1255 x: self.x.div(rhs),
1256 y: self.y.div(rhs),
1257 z: self.z.div(rhs),
1258 }
1259 }
1260}
1261
1262impl Div<&f32> for Vec3 {
1263 type Output = Vec3;
1264 #[inline]
1265 fn div(self, rhs: &f32) -> Vec3 {
1266 self.div(*rhs)
1267 }
1268}
1269
1270impl Div<&f32> for &Vec3 {
1271 type Output = Vec3;
1272 #[inline]
1273 fn div(self, rhs: &f32) -> Vec3 {
1274 (*self).div(*rhs)
1275 }
1276}
1277
1278impl Div<f32> for &Vec3 {
1279 type Output = Vec3;
1280 #[inline]
1281 fn div(self, rhs: f32) -> Vec3 {
1282 (*self).div(rhs)
1283 }
1284}
1285
1286impl DivAssign<f32> for Vec3 {
1287 #[inline]
1288 fn div_assign(&mut self, rhs: f32) {
1289 self.x.div_assign(rhs);
1290 self.y.div_assign(rhs);
1291 self.z.div_assign(rhs);
1292 }
1293}
1294
1295impl DivAssign<&f32> for Vec3 {
1296 #[inline]
1297 fn div_assign(&mut self, rhs: &f32) {
1298 self.div_assign(*rhs)
1299 }
1300}
1301
1302impl Div<Vec3> for f32 {
1303 type Output = Vec3;
1304 #[inline]
1305 fn div(self, rhs: Vec3) -> Vec3 {
1306 Vec3 {
1307 x: self.div(rhs.x),
1308 y: self.div(rhs.y),
1309 z: self.div(rhs.z),
1310 }
1311 }
1312}
1313
1314impl Div<&Vec3> for f32 {
1315 type Output = Vec3;
1316 #[inline]
1317 fn div(self, rhs: &Vec3) -> Vec3 {
1318 self.div(*rhs)
1319 }
1320}
1321
1322impl Div<&Vec3> for &f32 {
1323 type Output = Vec3;
1324 #[inline]
1325 fn div(self, rhs: &Vec3) -> Vec3 {
1326 (*self).div(*rhs)
1327 }
1328}
1329
1330impl Div<Vec3> for &f32 {
1331 type Output = Vec3;
1332 #[inline]
1333 fn div(self, rhs: Vec3) -> Vec3 {
1334 (*self).div(rhs)
1335 }
1336}
1337
1338impl Mul<Vec3> for Vec3 {
1339 type Output = Self;
1340 #[inline]
1341 fn mul(self, rhs: Self) -> Self {
1342 Self {
1343 x: self.x.mul(rhs.x),
1344 y: self.y.mul(rhs.y),
1345 z: self.z.mul(rhs.z),
1346 }
1347 }
1348}
1349
1350impl Mul<&Vec3> for Vec3 {
1351 type Output = Vec3;
1352 #[inline]
1353 fn mul(self, rhs: &Vec3) -> Vec3 {
1354 self.mul(*rhs)
1355 }
1356}
1357
1358impl Mul<&Vec3> for &Vec3 {
1359 type Output = Vec3;
1360 #[inline]
1361 fn mul(self, rhs: &Vec3) -> Vec3 {
1362 (*self).mul(*rhs)
1363 }
1364}
1365
1366impl Mul<Vec3> for &Vec3 {
1367 type Output = Vec3;
1368 #[inline]
1369 fn mul(self, rhs: Vec3) -> Vec3 {
1370 (*self).mul(rhs)
1371 }
1372}
1373
1374impl MulAssign<Vec3> for Vec3 {
1375 #[inline]
1376 fn mul_assign(&mut self, rhs: Self) {
1377 self.x.mul_assign(rhs.x);
1378 self.y.mul_assign(rhs.y);
1379 self.z.mul_assign(rhs.z);
1380 }
1381}
1382
1383impl MulAssign<&Vec3> for Vec3 {
1384 #[inline]
1385 fn mul_assign(&mut self, rhs: &Vec3) {
1386 self.mul_assign(*rhs)
1387 }
1388}
1389
1390impl Mul<f32> for Vec3 {
1391 type Output = Self;
1392 #[inline]
1393 fn mul(self, rhs: f32) -> Self {
1394 Self {
1395 x: self.x.mul(rhs),
1396 y: self.y.mul(rhs),
1397 z: self.z.mul(rhs),
1398 }
1399 }
1400}
1401
1402impl Mul<&f32> for Vec3 {
1403 type Output = Vec3;
1404 #[inline]
1405 fn mul(self, rhs: &f32) -> Vec3 {
1406 self.mul(*rhs)
1407 }
1408}
1409
1410impl Mul<&f32> for &Vec3 {
1411 type Output = Vec3;
1412 #[inline]
1413 fn mul(self, rhs: &f32) -> Vec3 {
1414 (*self).mul(*rhs)
1415 }
1416}
1417
1418impl Mul<f32> for &Vec3 {
1419 type Output = Vec3;
1420 #[inline]
1421 fn mul(self, rhs: f32) -> Vec3 {
1422 (*self).mul(rhs)
1423 }
1424}
1425
1426impl MulAssign<f32> for Vec3 {
1427 #[inline]
1428 fn mul_assign(&mut self, rhs: f32) {
1429 self.x.mul_assign(rhs);
1430 self.y.mul_assign(rhs);
1431 self.z.mul_assign(rhs);
1432 }
1433}
1434
1435impl MulAssign<&f32> for Vec3 {
1436 #[inline]
1437 fn mul_assign(&mut self, rhs: &f32) {
1438 self.mul_assign(*rhs)
1439 }
1440}
1441
1442impl Mul<Vec3> for f32 {
1443 type Output = Vec3;
1444 #[inline]
1445 fn mul(self, rhs: Vec3) -> Vec3 {
1446 Vec3 {
1447 x: self.mul(rhs.x),
1448 y: self.mul(rhs.y),
1449 z: self.mul(rhs.z),
1450 }
1451 }
1452}
1453
1454impl Mul<&Vec3> for f32 {
1455 type Output = Vec3;
1456 #[inline]
1457 fn mul(self, rhs: &Vec3) -> Vec3 {
1458 self.mul(*rhs)
1459 }
1460}
1461
1462impl Mul<&Vec3> for &f32 {
1463 type Output = Vec3;
1464 #[inline]
1465 fn mul(self, rhs: &Vec3) -> Vec3 {
1466 (*self).mul(*rhs)
1467 }
1468}
1469
1470impl Mul<Vec3> for &f32 {
1471 type Output = Vec3;
1472 #[inline]
1473 fn mul(self, rhs: Vec3) -> Vec3 {
1474 (*self).mul(rhs)
1475 }
1476}
1477
1478impl Add<Vec3> for Vec3 {
1479 type Output = Self;
1480 #[inline]
1481 fn add(self, rhs: Self) -> Self {
1482 Self {
1483 x: self.x.add(rhs.x),
1484 y: self.y.add(rhs.y),
1485 z: self.z.add(rhs.z),
1486 }
1487 }
1488}
1489
1490impl Add<&Vec3> for Vec3 {
1491 type Output = Vec3;
1492 #[inline]
1493 fn add(self, rhs: &Vec3) -> Vec3 {
1494 self.add(*rhs)
1495 }
1496}
1497
1498impl Add<&Vec3> for &Vec3 {
1499 type Output = Vec3;
1500 #[inline]
1501 fn add(self, rhs: &Vec3) -> Vec3 {
1502 (*self).add(*rhs)
1503 }
1504}
1505
1506impl Add<Vec3> for &Vec3 {
1507 type Output = Vec3;
1508 #[inline]
1509 fn add(self, rhs: Vec3) -> Vec3 {
1510 (*self).add(rhs)
1511 }
1512}
1513
1514impl AddAssign<Vec3> for Vec3 {
1515 #[inline]
1516 fn add_assign(&mut self, rhs: Self) {
1517 self.x.add_assign(rhs.x);
1518 self.y.add_assign(rhs.y);
1519 self.z.add_assign(rhs.z);
1520 }
1521}
1522
1523impl AddAssign<&Vec3> for Vec3 {
1524 #[inline]
1525 fn add_assign(&mut self, rhs: &Vec3) {
1526 self.add_assign(*rhs)
1527 }
1528}
1529
1530impl Add<f32> for Vec3 {
1531 type Output = Self;
1532 #[inline]
1533 fn add(self, rhs: f32) -> Self {
1534 Self {
1535 x: self.x.add(rhs),
1536 y: self.y.add(rhs),
1537 z: self.z.add(rhs),
1538 }
1539 }
1540}
1541
1542impl Add<&f32> for Vec3 {
1543 type Output = Vec3;
1544 #[inline]
1545 fn add(self, rhs: &f32) -> Vec3 {
1546 self.add(*rhs)
1547 }
1548}
1549
1550impl Add<&f32> for &Vec3 {
1551 type Output = Vec3;
1552 #[inline]
1553 fn add(self, rhs: &f32) -> Vec3 {
1554 (*self).add(*rhs)
1555 }
1556}
1557
1558impl Add<f32> for &Vec3 {
1559 type Output = Vec3;
1560 #[inline]
1561 fn add(self, rhs: f32) -> Vec3 {
1562 (*self).add(rhs)
1563 }
1564}
1565
1566impl AddAssign<f32> for Vec3 {
1567 #[inline]
1568 fn add_assign(&mut self, rhs: f32) {
1569 self.x.add_assign(rhs);
1570 self.y.add_assign(rhs);
1571 self.z.add_assign(rhs);
1572 }
1573}
1574
1575impl AddAssign<&f32> for Vec3 {
1576 #[inline]
1577 fn add_assign(&mut self, rhs: &f32) {
1578 self.add_assign(*rhs)
1579 }
1580}
1581
1582impl Add<Vec3> for f32 {
1583 type Output = Vec3;
1584 #[inline]
1585 fn add(self, rhs: Vec3) -> Vec3 {
1586 Vec3 {
1587 x: self.add(rhs.x),
1588 y: self.add(rhs.y),
1589 z: self.add(rhs.z),
1590 }
1591 }
1592}
1593
1594impl Add<&Vec3> for f32 {
1595 type Output = Vec3;
1596 #[inline]
1597 fn add(self, rhs: &Vec3) -> Vec3 {
1598 self.add(*rhs)
1599 }
1600}
1601
1602impl Add<&Vec3> for &f32 {
1603 type Output = Vec3;
1604 #[inline]
1605 fn add(self, rhs: &Vec3) -> Vec3 {
1606 (*self).add(*rhs)
1607 }
1608}
1609
1610impl Add<Vec3> for &f32 {
1611 type Output = Vec3;
1612 #[inline]
1613 fn add(self, rhs: Vec3) -> Vec3 {
1614 (*self).add(rhs)
1615 }
1616}
1617
1618impl Sub<Vec3> for Vec3 {
1619 type Output = Self;
1620 #[inline]
1621 fn sub(self, rhs: Self) -> Self {
1622 Self {
1623 x: self.x.sub(rhs.x),
1624 y: self.y.sub(rhs.y),
1625 z: self.z.sub(rhs.z),
1626 }
1627 }
1628}
1629
1630impl Sub<&Vec3> for Vec3 {
1631 type Output = Vec3;
1632 #[inline]
1633 fn sub(self, rhs: &Vec3) -> Vec3 {
1634 self.sub(*rhs)
1635 }
1636}
1637
1638impl Sub<&Vec3> for &Vec3 {
1639 type Output = Vec3;
1640 #[inline]
1641 fn sub(self, rhs: &Vec3) -> Vec3 {
1642 (*self).sub(*rhs)
1643 }
1644}
1645
1646impl Sub<Vec3> for &Vec3 {
1647 type Output = Vec3;
1648 #[inline]
1649 fn sub(self, rhs: Vec3) -> Vec3 {
1650 (*self).sub(rhs)
1651 }
1652}
1653
1654impl SubAssign<Vec3> for Vec3 {
1655 #[inline]
1656 fn sub_assign(&mut self, rhs: Vec3) {
1657 self.x.sub_assign(rhs.x);
1658 self.y.sub_assign(rhs.y);
1659 self.z.sub_assign(rhs.z);
1660 }
1661}
1662
1663impl SubAssign<&Vec3> for Vec3 {
1664 #[inline]
1665 fn sub_assign(&mut self, rhs: &Vec3) {
1666 self.sub_assign(*rhs)
1667 }
1668}
1669
1670impl Sub<f32> for Vec3 {
1671 type Output = Self;
1672 #[inline]
1673 fn sub(self, rhs: f32) -> Self {
1674 Self {
1675 x: self.x.sub(rhs),
1676 y: self.y.sub(rhs),
1677 z: self.z.sub(rhs),
1678 }
1679 }
1680}
1681
1682impl Sub<&f32> for Vec3 {
1683 type Output = Vec3;
1684 #[inline]
1685 fn sub(self, rhs: &f32) -> Vec3 {
1686 self.sub(*rhs)
1687 }
1688}
1689
1690impl Sub<&f32> for &Vec3 {
1691 type Output = Vec3;
1692 #[inline]
1693 fn sub(self, rhs: &f32) -> Vec3 {
1694 (*self).sub(*rhs)
1695 }
1696}
1697
1698impl Sub<f32> for &Vec3 {
1699 type Output = Vec3;
1700 #[inline]
1701 fn sub(self, rhs: f32) -> Vec3 {
1702 (*self).sub(rhs)
1703 }
1704}
1705
1706impl SubAssign<f32> for Vec3 {
1707 #[inline]
1708 fn sub_assign(&mut self, rhs: f32) {
1709 self.x.sub_assign(rhs);
1710 self.y.sub_assign(rhs);
1711 self.z.sub_assign(rhs);
1712 }
1713}
1714
1715impl SubAssign<&f32> for Vec3 {
1716 #[inline]
1717 fn sub_assign(&mut self, rhs: &f32) {
1718 self.sub_assign(*rhs)
1719 }
1720}
1721
1722impl Sub<Vec3> for f32 {
1723 type Output = Vec3;
1724 #[inline]
1725 fn sub(self, rhs: Vec3) -> Vec3 {
1726 Vec3 {
1727 x: self.sub(rhs.x),
1728 y: self.sub(rhs.y),
1729 z: self.sub(rhs.z),
1730 }
1731 }
1732}
1733
1734impl Sub<&Vec3> for f32 {
1735 type Output = Vec3;
1736 #[inline]
1737 fn sub(self, rhs: &Vec3) -> Vec3 {
1738 self.sub(*rhs)
1739 }
1740}
1741
1742impl Sub<&Vec3> for &f32 {
1743 type Output = Vec3;
1744 #[inline]
1745 fn sub(self, rhs: &Vec3) -> Vec3 {
1746 (*self).sub(*rhs)
1747 }
1748}
1749
1750impl Sub<Vec3> for &f32 {
1751 type Output = Vec3;
1752 #[inline]
1753 fn sub(self, rhs: Vec3) -> Vec3 {
1754 (*self).sub(rhs)
1755 }
1756}
1757
1758impl Rem<Vec3> for Vec3 {
1759 type Output = Self;
1760 #[inline]
1761 fn rem(self, rhs: Self) -> Self {
1762 Self {
1763 x: self.x.rem(rhs.x),
1764 y: self.y.rem(rhs.y),
1765 z: self.z.rem(rhs.z),
1766 }
1767 }
1768}
1769
1770impl Rem<&Vec3> for Vec3 {
1771 type Output = Vec3;
1772 #[inline]
1773 fn rem(self, rhs: &Vec3) -> Vec3 {
1774 self.rem(*rhs)
1775 }
1776}
1777
1778impl Rem<&Vec3> for &Vec3 {
1779 type Output = Vec3;
1780 #[inline]
1781 fn rem(self, rhs: &Vec3) -> Vec3 {
1782 (*self).rem(*rhs)
1783 }
1784}
1785
1786impl Rem<Vec3> for &Vec3 {
1787 type Output = Vec3;
1788 #[inline]
1789 fn rem(self, rhs: Vec3) -> Vec3 {
1790 (*self).rem(rhs)
1791 }
1792}
1793
1794impl RemAssign<Vec3> for Vec3 {
1795 #[inline]
1796 fn rem_assign(&mut self, rhs: Self) {
1797 self.x.rem_assign(rhs.x);
1798 self.y.rem_assign(rhs.y);
1799 self.z.rem_assign(rhs.z);
1800 }
1801}
1802
1803impl RemAssign<&Vec3> for Vec3 {
1804 #[inline]
1805 fn rem_assign(&mut self, rhs: &Vec3) {
1806 self.rem_assign(*rhs)
1807 }
1808}
1809
1810impl Rem<f32> for Vec3 {
1811 type Output = Self;
1812 #[inline]
1813 fn rem(self, rhs: f32) -> Self {
1814 Self {
1815 x: self.x.rem(rhs),
1816 y: self.y.rem(rhs),
1817 z: self.z.rem(rhs),
1818 }
1819 }
1820}
1821
1822impl Rem<&f32> for Vec3 {
1823 type Output = Vec3;
1824 #[inline]
1825 fn rem(self, rhs: &f32) -> Vec3 {
1826 self.rem(*rhs)
1827 }
1828}
1829
1830impl Rem<&f32> for &Vec3 {
1831 type Output = Vec3;
1832 #[inline]
1833 fn rem(self, rhs: &f32) -> Vec3 {
1834 (*self).rem(*rhs)
1835 }
1836}
1837
1838impl Rem<f32> for &Vec3 {
1839 type Output = Vec3;
1840 #[inline]
1841 fn rem(self, rhs: f32) -> Vec3 {
1842 (*self).rem(rhs)
1843 }
1844}
1845
1846impl RemAssign<f32> for Vec3 {
1847 #[inline]
1848 fn rem_assign(&mut self, rhs: f32) {
1849 self.x.rem_assign(rhs);
1850 self.y.rem_assign(rhs);
1851 self.z.rem_assign(rhs);
1852 }
1853}
1854
1855impl RemAssign<&f32> for Vec3 {
1856 #[inline]
1857 fn rem_assign(&mut self, rhs: &f32) {
1858 self.rem_assign(*rhs)
1859 }
1860}
1861
1862impl Rem<Vec3> for f32 {
1863 type Output = Vec3;
1864 #[inline]
1865 fn rem(self, rhs: Vec3) -> Vec3 {
1866 Vec3 {
1867 x: self.rem(rhs.x),
1868 y: self.rem(rhs.y),
1869 z: self.rem(rhs.z),
1870 }
1871 }
1872}
1873
1874impl Rem<&Vec3> for f32 {
1875 type Output = Vec3;
1876 #[inline]
1877 fn rem(self, rhs: &Vec3) -> Vec3 {
1878 self.rem(*rhs)
1879 }
1880}
1881
1882impl Rem<&Vec3> for &f32 {
1883 type Output = Vec3;
1884 #[inline]
1885 fn rem(self, rhs: &Vec3) -> Vec3 {
1886 (*self).rem(*rhs)
1887 }
1888}
1889
1890impl Rem<Vec3> for &f32 {
1891 type Output = Vec3;
1892 #[inline]
1893 fn rem(self, rhs: Vec3) -> Vec3 {
1894 (*self).rem(rhs)
1895 }
1896}
1897
1898#[cfg(not(target_arch = "spirv"))]
1899impl AsRef<[f32; 3]> for Vec3 {
1900 #[inline]
1901 fn as_ref(&self) -> &[f32; 3] {
1902 unsafe { &*(self as *const Vec3 as *const [f32; 3]) }
1903 }
1904}
1905
1906#[cfg(not(target_arch = "spirv"))]
1907impl AsMut<[f32; 3]> for Vec3 {
1908 #[inline]
1909 fn as_mut(&mut self) -> &mut [f32; 3] {
1910 unsafe { &mut *(self as *mut Vec3 as *mut [f32; 3]) }
1911 }
1912}
1913
1914impl Sum for Vec3 {
1915 #[inline]
1916 fn sum<I>(iter: I) -> Self
1917 where
1918 I: Iterator<Item = Self>,
1919 {
1920 iter.fold(Self::ZERO, Self::add)
1921 }
1922}
1923
1924impl<'a> Sum<&'a Self> for Vec3 {
1925 #[inline]
1926 fn sum<I>(iter: I) -> Self
1927 where
1928 I: Iterator<Item = &'a Self>,
1929 {
1930 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
1931 }
1932}
1933
1934impl Product for Vec3 {
1935 #[inline]
1936 fn product<I>(iter: I) -> Self
1937 where
1938 I: Iterator<Item = Self>,
1939 {
1940 iter.fold(Self::ONE, Self::mul)
1941 }
1942}
1943
1944impl<'a> Product<&'a Self> for Vec3 {
1945 #[inline]
1946 fn product<I>(iter: I) -> Self
1947 where
1948 I: Iterator<Item = &'a Self>,
1949 {
1950 iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
1951 }
1952}
1953
1954impl Neg for Vec3 {
1955 type Output = Self;
1956 #[inline]
1957 fn neg(self) -> Self {
1958 Self {
1959 x: self.x.neg(),
1960 y: self.y.neg(),
1961 z: self.z.neg(),
1962 }
1963 }
1964}
1965
1966impl Neg for &Vec3 {
1967 type Output = Vec3;
1968 #[inline]
1969 fn neg(self) -> Vec3 {
1970 (*self).neg()
1971 }
1972}
1973
1974impl Index<usize> for Vec3 {
1975 type Output = f32;
1976 #[inline]
1977 fn index(&self, index: usize) -> &Self::Output {
1978 match index {
1979 0 => &self.x,
1980 1 => &self.y,
1981 2 => &self.z,
1982 _ => panic!("index out of bounds"),
1983 }
1984 }
1985}
1986
1987impl IndexMut<usize> for Vec3 {
1988 #[inline]
1989 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1990 match index {
1991 0 => &mut self.x,
1992 1 => &mut self.y,
1993 2 => &mut self.z,
1994 _ => panic!("index out of bounds"),
1995 }
1996 }
1997}
1998
1999impl fmt::Display for Vec3 {
2000 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2001 if let Some(p) = f.precision() {
2002 write!(f, "[{:.*}, {:.*}, {:.*}]", p, self.x, p, self.y, p, self.z)
2003 } else {
2004 write!(f, "[{}, {}, {}]", self.x, self.y, self.z)
2005 }
2006 }
2007}
2008
2009impl fmt::Debug for Vec3 {
2010 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
2011 fmt.debug_tuple(stringify!(Vec3))
2012 .field(&self.x)
2013 .field(&self.y)
2014 .field(&self.z)
2015 .finish()
2016 }
2017}
2018
2019impl From<[f32; 3]> for Vec3 {
2020 #[inline]
2021 fn from(a: [f32; 3]) -> Self {
2022 Self::new(a[0], a[1], a[2])
2023 }
2024}
2025
2026impl From<Vec3> for [f32; 3] {
2027 #[inline]
2028 fn from(v: Vec3) -> Self {
2029 [v.x, v.y, v.z]
2030 }
2031}
2032
2033impl From<(f32, f32, f32)> for Vec3 {
2034 #[inline]
2035 fn from(t: (f32, f32, f32)) -> Self {
2036 Self::new(t.0, t.1, t.2)
2037 }
2038}
2039
2040impl From<Vec3> for (f32, f32, f32) {
2041 #[inline]
2042 fn from(v: Vec3) -> Self {
2043 (v.x, v.y, v.z)
2044 }
2045}
2046
2047impl From<(Vec2, f32)> for Vec3 {
2048 #[inline]
2049 fn from((v, z): (Vec2, f32)) -> Self {
2050 Self::new(v.x, v.y, z)
2051 }
2052}
2053
2054impl From<BVec3> for Vec3 {
2055 #[inline]
2056 fn from(v: BVec3) -> Self {
2057 Self::new(f32::from(v.x), f32::from(v.y), f32::from(v.z))
2058 }
2059}
2060
2061impl From<BVec3A> for Vec3 {
2062 #[inline]
2063 fn from(v: BVec3A) -> Self {
2064 let bool_array: [bool; 3] = v.into();
2065 Self::new(
2066 f32::from(bool_array[0]),
2067 f32::from(bool_array[1]),
2068 f32::from(bool_array[2]),
2069 )
2070 }
2071}