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 #[inline(always)]
74 #[must_use]
75 pub const fn new(x: f32, y: f32, z: f32) -> Self {
76 Self { x, y, z }
77 }
78
79 #[inline]
81 #[must_use]
82 pub const fn splat(v: f32) -> Self {
83 Self { x: v, y: v, z: v }
84 }
85
86 #[inline]
88 #[must_use]
89 pub fn map<F>(self, f: F) -> Self
90 where
91 F: Fn(f32) -> f32,
92 {
93 Self::new(f(self.x), f(self.y), f(self.z))
94 }
95
96 #[inline]
102 #[must_use]
103 pub fn select(mask: BVec3, 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 #[inline]
113 #[must_use]
114 pub const fn from_array(a: [f32; 3]) -> Self {
115 Self::new(a[0], a[1], a[2])
116 }
117
118 #[inline]
120 #[must_use]
121 pub const fn to_array(&self) -> [f32; 3] {
122 [self.x, self.y, self.z]
123 }
124
125 #[inline]
131 #[must_use]
132 pub const fn from_slice(slice: &[f32]) -> Self {
133 assert!(slice.len() >= 3);
134 Self::new(slice[0], slice[1], slice[2])
135 }
136
137 #[inline]
143 pub fn write_to_slice(self, slice: &mut [f32]) {
144 slice[..3].copy_from_slice(&self.to_array());
145 }
146
147 #[allow(dead_code)]
149 #[inline]
150 #[must_use]
151 pub(crate) fn from_vec4(v: Vec4) -> Self {
152 Self {
153 x: v.x,
154 y: v.y,
155 z: v.z,
156 }
157 }
158
159 #[inline]
161 #[must_use]
162 pub fn extend(self, w: f32) -> Vec4 {
163 Vec4::new(self.x, self.y, self.z, w)
164 }
165
166 #[inline]
170 #[must_use]
171 pub fn truncate(self) -> Vec2 {
172 use crate::swizzles::Vec3Swizzles;
173 self.xy()
174 }
175
176 #[inline]
178 #[must_use]
179 pub fn with_x(mut self, x: f32) -> Self {
180 self.x = x;
181 self
182 }
183
184 #[inline]
186 #[must_use]
187 pub fn with_y(mut self, y: f32) -> Self {
188 self.y = y;
189 self
190 }
191
192 #[inline]
194 #[must_use]
195 pub fn with_z(mut self, z: f32) -> Self {
196 self.z = z;
197 self
198 }
199
200 #[inline]
202 #[must_use]
203 pub fn dot(self, rhs: Self) -> f32 {
204 (self.x * rhs.x) + (self.y * rhs.y) + (self.z * rhs.z)
205 }
206
207 #[inline]
209 #[must_use]
210 pub fn dot_into_vec(self, rhs: Self) -> Self {
211 Self::splat(self.dot(rhs))
212 }
213
214 #[inline]
216 #[must_use]
217 pub fn cross(self, rhs: Self) -> Self {
218 Self {
219 x: self.y * rhs.z - rhs.y * self.z,
220 y: self.z * rhs.x - rhs.z * self.x,
221 z: self.x * rhs.y - rhs.x * self.y,
222 }
223 }
224
225 #[inline]
229 #[must_use]
230 pub fn min(self, rhs: Self) -> Self {
231 Self {
232 x: self.x.min(rhs.x),
233 y: self.y.min(rhs.y),
234 z: self.z.min(rhs.z),
235 }
236 }
237
238 #[inline]
242 #[must_use]
243 pub fn max(self, rhs: Self) -> Self {
244 Self {
245 x: self.x.max(rhs.x),
246 y: self.y.max(rhs.y),
247 z: self.z.max(rhs.z),
248 }
249 }
250
251 #[inline]
259 #[must_use]
260 pub fn clamp(self, min: Self, max: Self) -> Self {
261 glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
262 self.max(min).min(max)
263 }
264
265 #[inline]
269 #[must_use]
270 pub fn min_element(self) -> f32 {
271 self.x.min(self.y.min(self.z))
272 }
273
274 #[inline]
278 #[must_use]
279 pub fn max_element(self) -> f32 {
280 self.x.max(self.y.max(self.z))
281 }
282
283 #[doc(alias = "argmin")]
285 #[inline]
286 #[must_use]
287 pub fn min_position(self) -> usize {
288 let mut min = self.x;
289 let mut index = 0;
290 if self.y < min {
291 min = self.y;
292 index = 1;
293 }
294 if self.z < min {
295 index = 2;
296 }
297 index
298 }
299
300 #[doc(alias = "argmax")]
302 #[inline]
303 #[must_use]
304 pub fn max_position(self) -> usize {
305 let mut max = self.x;
306 let mut index = 0;
307 if self.y > max {
308 max = self.y;
309 index = 1;
310 }
311 if self.z > max {
312 index = 2;
313 }
314 index
315 }
316
317 #[inline]
321 #[must_use]
322 pub fn element_sum(self) -> f32 {
323 self.x + self.y + self.z
324 }
325
326 #[inline]
330 #[must_use]
331 pub fn element_product(self) -> f32 {
332 self.x * self.y * self.z
333 }
334
335 #[inline]
341 #[must_use]
342 pub fn cmpeq(self, rhs: Self) -> BVec3 {
343 BVec3::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y), self.z.eq(&rhs.z))
344 }
345
346 #[inline]
352 #[must_use]
353 pub fn cmpne(self, rhs: Self) -> BVec3 {
354 BVec3::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y), self.z.ne(&rhs.z))
355 }
356
357 #[inline]
363 #[must_use]
364 pub fn cmpge(self, rhs: Self) -> BVec3 {
365 BVec3::new(self.x.ge(&rhs.x), self.y.ge(&rhs.y), self.z.ge(&rhs.z))
366 }
367
368 #[inline]
374 #[must_use]
375 pub fn cmpgt(self, rhs: Self) -> BVec3 {
376 BVec3::new(self.x.gt(&rhs.x), self.y.gt(&rhs.y), self.z.gt(&rhs.z))
377 }
378
379 #[inline]
385 #[must_use]
386 pub fn cmple(self, rhs: Self) -> BVec3 {
387 BVec3::new(self.x.le(&rhs.x), self.y.le(&rhs.y), self.z.le(&rhs.z))
388 }
389
390 #[inline]
396 #[must_use]
397 pub fn cmplt(self, rhs: Self) -> BVec3 {
398 BVec3::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y), self.z.lt(&rhs.z))
399 }
400
401 #[inline]
403 #[must_use]
404 pub fn abs(self) -> Self {
405 Self {
406 x: math::abs(self.x),
407 y: math::abs(self.y),
408 z: math::abs(self.z),
409 }
410 }
411
412 #[inline]
418 #[must_use]
419 pub fn signum(self) -> Self {
420 Self {
421 x: math::signum(self.x),
422 y: math::signum(self.y),
423 z: math::signum(self.z),
424 }
425 }
426
427 #[inline]
429 #[must_use]
430 pub fn copysign(self, rhs: Self) -> Self {
431 Self {
432 x: math::copysign(self.x, rhs.x),
433 y: math::copysign(self.y, rhs.y),
434 z: math::copysign(self.z, rhs.z),
435 }
436 }
437
438 #[inline]
443 #[must_use]
444 pub fn is_negative_bitmask(self) -> u32 {
445 (self.x.is_sign_negative() as u32)
446 | ((self.y.is_sign_negative() as u32) << 1)
447 | ((self.z.is_sign_negative() as u32) << 2)
448 }
449
450 #[inline]
453 #[must_use]
454 pub fn is_finite(self) -> bool {
455 self.x.is_finite() && self.y.is_finite() && self.z.is_finite()
456 }
457
458 pub fn is_finite_mask(self) -> BVec3 {
462 BVec3::new(self.x.is_finite(), self.y.is_finite(), self.z.is_finite())
463 }
464
465 #[inline]
467 #[must_use]
468 pub fn is_nan(self) -> bool {
469 self.x.is_nan() || self.y.is_nan() || self.z.is_nan()
470 }
471
472 #[inline]
476 #[must_use]
477 pub fn is_nan_mask(self) -> BVec3 {
478 BVec3::new(self.x.is_nan(), self.y.is_nan(), self.z.is_nan())
479 }
480
481 #[doc(alias = "magnitude")]
483 #[inline]
484 #[must_use]
485 pub fn length(self) -> f32 {
486 math::sqrt(self.dot(self))
487 }
488
489 #[doc(alias = "magnitude2")]
493 #[inline]
494 #[must_use]
495 pub fn length_squared(self) -> f32 {
496 self.dot(self)
497 }
498
499 #[inline]
503 #[must_use]
504 pub fn length_recip(self) -> f32 {
505 self.length().recip()
506 }
507
508 #[inline]
510 #[must_use]
511 pub fn distance(self, rhs: Self) -> f32 {
512 (self - rhs).length()
513 }
514
515 #[inline]
517 #[must_use]
518 pub fn distance_squared(self, rhs: Self) -> f32 {
519 (self - rhs).length_squared()
520 }
521
522 #[inline]
524 #[must_use]
525 pub fn div_euclid(self, rhs: Self) -> Self {
526 Self::new(
527 math::div_euclid(self.x, rhs.x),
528 math::div_euclid(self.y, rhs.y),
529 math::div_euclid(self.z, rhs.z),
530 )
531 }
532
533 #[inline]
537 #[must_use]
538 pub fn rem_euclid(self, rhs: Self) -> Self {
539 Self::new(
540 math::rem_euclid(self.x, rhs.x),
541 math::rem_euclid(self.y, rhs.y),
542 math::rem_euclid(self.z, rhs.z),
543 )
544 }
545
546 #[inline]
556 #[must_use]
557 pub fn normalize(self) -> Self {
558 #[allow(clippy::let_and_return)]
559 let normalized = self.mul(self.length_recip());
560 glam_assert!(normalized.is_finite());
561 normalized
562 }
563
564 #[inline]
571 #[must_use]
572 pub fn try_normalize(self) -> Option<Self> {
573 let rcp = self.length_recip();
574 if rcp.is_finite() && rcp > 0.0 {
575 Some(self * rcp)
576 } else {
577 None
578 }
579 }
580
581 #[inline]
589 #[must_use]
590 pub fn normalize_or(self, fallback: Self) -> Self {
591 let rcp = self.length_recip();
592 if rcp.is_finite() && rcp > 0.0 {
593 self * rcp
594 } else {
595 fallback
596 }
597 }
598
599 #[inline]
606 #[must_use]
607 pub fn normalize_or_zero(self) -> Self {
608 self.normalize_or(Self::ZERO)
609 }
610
611 #[inline]
615 #[must_use]
616 pub fn is_normalized(self) -> bool {
617 math::abs(self.length_squared() - 1.0) <= 2e-4
618 }
619
620 #[inline]
628 #[must_use]
629 pub fn project_onto(self, rhs: Self) -> Self {
630 let other_len_sq_rcp = rhs.dot(rhs).recip();
631 glam_assert!(other_len_sq_rcp.is_finite());
632 rhs * self.dot(rhs) * other_len_sq_rcp
633 }
634
635 #[doc(alias("plane"))]
646 #[inline]
647 #[must_use]
648 pub fn reject_from(self, rhs: Self) -> Self {
649 self - self.project_onto(rhs)
650 }
651
652 #[inline]
660 #[must_use]
661 pub fn project_onto_normalized(self, rhs: Self) -> Self {
662 glam_assert!(rhs.is_normalized());
663 rhs * self.dot(rhs)
664 }
665
666 #[doc(alias("plane"))]
677 #[inline]
678 #[must_use]
679 pub fn reject_from_normalized(self, rhs: Self) -> Self {
680 self - self.project_onto_normalized(rhs)
681 }
682
683 #[inline]
686 #[must_use]
687 pub fn round(self) -> Self {
688 Self {
689 x: math::round(self.x),
690 y: math::round(self.y),
691 z: math::round(self.z),
692 }
693 }
694
695 #[inline]
698 #[must_use]
699 pub fn floor(self) -> Self {
700 Self {
701 x: math::floor(self.x),
702 y: math::floor(self.y),
703 z: math::floor(self.z),
704 }
705 }
706
707 #[inline]
710 #[must_use]
711 pub fn ceil(self) -> Self {
712 Self {
713 x: math::ceil(self.x),
714 y: math::ceil(self.y),
715 z: math::ceil(self.z),
716 }
717 }
718
719 #[inline]
722 #[must_use]
723 pub fn trunc(self) -> Self {
724 Self {
725 x: math::trunc(self.x),
726 y: math::trunc(self.y),
727 z: math::trunc(self.z),
728 }
729 }
730
731 #[inline]
738 #[must_use]
739 pub fn fract(self) -> Self {
740 self - self.trunc()
741 }
742
743 #[inline]
750 #[must_use]
751 pub fn fract_gl(self) -> Self {
752 self - self.floor()
753 }
754
755 #[inline]
758 #[must_use]
759 pub fn exp(self) -> Self {
760 Self::new(math::exp(self.x), math::exp(self.y), math::exp(self.z))
761 }
762
763 #[inline]
765 #[must_use]
766 pub fn powf(self, n: f32) -> Self {
767 Self::new(
768 math::powf(self.x, n),
769 math::powf(self.y, n),
770 math::powf(self.z, n),
771 )
772 }
773
774 #[inline]
776 #[must_use]
777 pub fn recip(self) -> Self {
778 Self {
779 x: 1.0 / self.x,
780 y: 1.0 / self.y,
781 z: 1.0 / self.z,
782 }
783 }
784
785 #[doc(alias = "mix")]
791 #[inline]
792 #[must_use]
793 pub fn lerp(self, rhs: Self, s: f32) -> Self {
794 self * (1.0 - s) + rhs * s
795 }
796
797 #[inline]
802 #[must_use]
803 pub fn move_towards(&self, rhs: Self, d: f32) -> Self {
804 let a = rhs - *self;
805 let len = a.length();
806 if len <= d || len <= 1e-4 {
807 return rhs;
808 }
809 *self + a / len * d
810 }
811
812 #[inline]
818 pub fn midpoint(self, rhs: Self) -> Self {
819 (self + rhs) * 0.5
820 }
821
822 #[inline]
832 #[must_use]
833 pub fn abs_diff_eq(self, rhs: Self, max_abs_diff: f32) -> bool {
834 self.sub(rhs).abs().cmple(Self::splat(max_abs_diff)).all()
835 }
836
837 #[inline]
843 #[must_use]
844 pub fn clamp_length(self, min: f32, max: f32) -> Self {
845 glam_assert!(0.0 <= min);
846 glam_assert!(min <= max);
847 let length_sq = self.length_squared();
848 if length_sq < min * min {
849 min * (self / math::sqrt(length_sq))
850 } else if length_sq > max * max {
851 max * (self / math::sqrt(length_sq))
852 } else {
853 self
854 }
855 }
856
857 #[inline]
863 #[must_use]
864 pub fn clamp_length_max(self, max: f32) -> Self {
865 glam_assert!(0.0 <= max);
866 let length_sq = self.length_squared();
867 if length_sq > max * max {
868 max * (self / math::sqrt(length_sq))
869 } else {
870 self
871 }
872 }
873
874 #[inline]
880 #[must_use]
881 pub fn clamp_length_min(self, min: f32) -> Self {
882 glam_assert!(0.0 <= min);
883 let length_sq = self.length_squared();
884 if length_sq < min * min {
885 min * (self / math::sqrt(length_sq))
886 } else {
887 self
888 }
889 }
890
891 #[inline]
899 #[must_use]
900 pub fn mul_add(self, a: Self, b: Self) -> Self {
901 Self::new(
902 math::mul_add(self.x, a.x, b.x),
903 math::mul_add(self.y, a.y, b.y),
904 math::mul_add(self.z, a.z, b.z),
905 )
906 }
907
908 #[inline]
917 #[must_use]
918 pub fn reflect(self, normal: Self) -> Self {
919 glam_assert!(normal.is_normalized());
920 self - 2.0 * self.dot(normal) * normal
921 }
922
923 #[inline]
933 #[must_use]
934 pub fn refract(self, normal: Self, eta: f32) -> Self {
935 glam_assert!(self.is_normalized());
936 glam_assert!(normal.is_normalized());
937 let n_dot_i = normal.dot(self);
938 let k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
939 if k >= 0.0 {
940 eta * self - (eta * n_dot_i + math::sqrt(k)) * normal
941 } else {
942 Self::ZERO
943 }
944 }
945
946 #[inline]
950 #[must_use]
951 pub fn angle_between(self, rhs: Self) -> f32 {
952 math::acos_approx(
953 self.dot(rhs)
954 .div(math::sqrt(self.length_squared().mul(rhs.length_squared()))),
955 )
956 }
957
958 #[inline]
964 #[must_use]
965 pub fn rotate_towards(self, rhs: Self, max_angle: f32) -> Self {
966 let angle_between = self.angle_between(rhs);
967 let angle = max_angle.clamp(angle_between - core::f32::consts::PI, angle_between);
969 let axis = self
970 .cross(rhs)
971 .try_normalize()
972 .unwrap_or_else(|| self.any_orthogonal_vector().normalize());
973 Quat::from_axis_angle(axis, angle) * self
974 }
975
976 #[inline]
983 #[must_use]
984 pub fn any_orthogonal_vector(&self) -> Self {
985 if math::abs(self.x) > math::abs(self.y) {
987 Self::new(-self.z, 0.0, self.x) } else {
989 Self::new(0.0, self.z, -self.y) }
991 }
992
993 #[inline]
1001 #[must_use]
1002 pub fn any_orthonormal_vector(&self) -> Self {
1003 glam_assert!(self.is_normalized());
1004 let sign = math::signum(self.z);
1006 let a = -1.0 / (sign + self.z);
1007 let b = self.x * self.y * a;
1008 Self::new(b, sign + self.y * self.y * a, -self.y)
1009 }
1010
1011 #[inline]
1018 #[must_use]
1019 pub fn any_orthonormal_pair(&self) -> (Self, Self) {
1020 glam_assert!(self.is_normalized());
1021 let sign = math::signum(self.z);
1023 let a = -1.0 / (sign + self.z);
1024 let b = self.x * self.y * a;
1025 (
1026 Self::new(1.0 + sign * self.x * self.x * a, sign * b, -sign * self.x),
1027 Self::new(b, sign + self.y * self.y * a, -self.y),
1028 )
1029 }
1030
1031 #[inline]
1037 #[must_use]
1038 pub fn slerp(self, rhs: Self, s: f32) -> Self {
1039 let self_length = self.length();
1040 let rhs_length = rhs.length();
1041 let dot = self.dot(rhs) / (self_length * rhs_length);
1043 if math::abs(dot) < 1.0 - 3e-7 {
1045 let theta = math::acos_approx(dot);
1047 let sin_theta = math::sin(theta);
1049 let t1 = math::sin(theta * (1. - s));
1050 let t2 = math::sin(theta * s);
1051
1052 let result_length = self_length.lerp(rhs_length, s);
1054 return (self * (result_length / self_length) * t1
1056 + rhs * (result_length / rhs_length) * t2)
1057 * sin_theta.recip();
1058 }
1059 if dot < 0.0 {
1060 let axis = self.any_orthogonal_vector().normalize();
1064 let rotation = Quat::from_axis_angle(axis, core::f32::consts::PI * s);
1065 let result_length = self_length.lerp(rhs_length, s);
1067 rotation * self * (result_length / self_length)
1068 } else {
1069 self.lerp(rhs, s)
1071 }
1072 }
1073
1074 #[inline]
1076 #[must_use]
1077 pub fn as_dvec3(&self) -> crate::DVec3 {
1078 crate::DVec3::new(self.x as f64, self.y as f64, self.z as f64)
1079 }
1080
1081 #[inline]
1083 #[must_use]
1084 pub fn as_i8vec3(&self) -> crate::I8Vec3 {
1085 crate::I8Vec3::new(self.x as i8, self.y as i8, self.z as i8)
1086 }
1087
1088 #[inline]
1090 #[must_use]
1091 pub fn as_u8vec3(&self) -> crate::U8Vec3 {
1092 crate::U8Vec3::new(self.x as u8, self.y as u8, self.z as u8)
1093 }
1094
1095 #[inline]
1097 #[must_use]
1098 pub fn as_i16vec3(&self) -> crate::I16Vec3 {
1099 crate::I16Vec3::new(self.x as i16, self.y as i16, self.z as i16)
1100 }
1101
1102 #[inline]
1104 #[must_use]
1105 pub fn as_u16vec3(&self) -> crate::U16Vec3 {
1106 crate::U16Vec3::new(self.x as u16, self.y as u16, self.z as u16)
1107 }
1108
1109 #[inline]
1111 #[must_use]
1112 pub fn as_ivec3(&self) -> crate::IVec3 {
1113 crate::IVec3::new(self.x as i32, self.y as i32, self.z as i32)
1114 }
1115
1116 #[inline]
1118 #[must_use]
1119 pub fn as_uvec3(&self) -> crate::UVec3 {
1120 crate::UVec3::new(self.x as u32, self.y as u32, self.z as u32)
1121 }
1122
1123 #[inline]
1125 #[must_use]
1126 pub fn as_i64vec3(&self) -> crate::I64Vec3 {
1127 crate::I64Vec3::new(self.x as i64, self.y as i64, self.z as i64)
1128 }
1129
1130 #[inline]
1132 #[must_use]
1133 pub fn as_u64vec3(&self) -> crate::U64Vec3 {
1134 crate::U64Vec3::new(self.x as u64, self.y as u64, self.z as u64)
1135 }
1136
1137 #[inline]
1139 #[must_use]
1140 pub fn as_usizevec3(&self) -> crate::USizeVec3 {
1141 crate::USizeVec3::new(self.x as usize, self.y as usize, self.z as usize)
1142 }
1143}
1144
1145impl Default for Vec3 {
1146 #[inline(always)]
1147 fn default() -> Self {
1148 Self::ZERO
1149 }
1150}
1151
1152impl Div<Vec3> for Vec3 {
1153 type Output = Self;
1154 #[inline]
1155 fn div(self, rhs: Self) -> Self {
1156 Self {
1157 x: self.x.div(rhs.x),
1158 y: self.y.div(rhs.y),
1159 z: self.z.div(rhs.z),
1160 }
1161 }
1162}
1163
1164impl Div<&Vec3> for Vec3 {
1165 type Output = Vec3;
1166 #[inline]
1167 fn div(self, rhs: &Vec3) -> Vec3 {
1168 self.div(*rhs)
1169 }
1170}
1171
1172impl Div<&Vec3> for &Vec3 {
1173 type Output = Vec3;
1174 #[inline]
1175 fn div(self, rhs: &Vec3) -> Vec3 {
1176 (*self).div(*rhs)
1177 }
1178}
1179
1180impl Div<Vec3> for &Vec3 {
1181 type Output = Vec3;
1182 #[inline]
1183 fn div(self, rhs: Vec3) -> Vec3 {
1184 (*self).div(rhs)
1185 }
1186}
1187
1188impl DivAssign<Vec3> for Vec3 {
1189 #[inline]
1190 fn div_assign(&mut self, rhs: Self) {
1191 self.x.div_assign(rhs.x);
1192 self.y.div_assign(rhs.y);
1193 self.z.div_assign(rhs.z);
1194 }
1195}
1196
1197impl DivAssign<&Vec3> for Vec3 {
1198 #[inline]
1199 fn div_assign(&mut self, rhs: &Vec3) {
1200 self.div_assign(*rhs)
1201 }
1202}
1203
1204impl Div<f32> for Vec3 {
1205 type Output = Self;
1206 #[inline]
1207 fn div(self, rhs: f32) -> Self {
1208 Self {
1209 x: self.x.div(rhs),
1210 y: self.y.div(rhs),
1211 z: self.z.div(rhs),
1212 }
1213 }
1214}
1215
1216impl Div<&f32> for Vec3 {
1217 type Output = Vec3;
1218 #[inline]
1219 fn div(self, rhs: &f32) -> Vec3 {
1220 self.div(*rhs)
1221 }
1222}
1223
1224impl Div<&f32> for &Vec3 {
1225 type Output = Vec3;
1226 #[inline]
1227 fn div(self, rhs: &f32) -> Vec3 {
1228 (*self).div(*rhs)
1229 }
1230}
1231
1232impl Div<f32> for &Vec3 {
1233 type Output = Vec3;
1234 #[inline]
1235 fn div(self, rhs: f32) -> Vec3 {
1236 (*self).div(rhs)
1237 }
1238}
1239
1240impl DivAssign<f32> for Vec3 {
1241 #[inline]
1242 fn div_assign(&mut self, rhs: f32) {
1243 self.x.div_assign(rhs);
1244 self.y.div_assign(rhs);
1245 self.z.div_assign(rhs);
1246 }
1247}
1248
1249impl DivAssign<&f32> for Vec3 {
1250 #[inline]
1251 fn div_assign(&mut self, rhs: &f32) {
1252 self.div_assign(*rhs)
1253 }
1254}
1255
1256impl Div<Vec3> for f32 {
1257 type Output = Vec3;
1258 #[inline]
1259 fn div(self, rhs: Vec3) -> Vec3 {
1260 Vec3 {
1261 x: self.div(rhs.x),
1262 y: self.div(rhs.y),
1263 z: self.div(rhs.z),
1264 }
1265 }
1266}
1267
1268impl Div<&Vec3> for f32 {
1269 type Output = Vec3;
1270 #[inline]
1271 fn div(self, rhs: &Vec3) -> Vec3 {
1272 self.div(*rhs)
1273 }
1274}
1275
1276impl Div<&Vec3> for &f32 {
1277 type Output = Vec3;
1278 #[inline]
1279 fn div(self, rhs: &Vec3) -> Vec3 {
1280 (*self).div(*rhs)
1281 }
1282}
1283
1284impl Div<Vec3> for &f32 {
1285 type Output = Vec3;
1286 #[inline]
1287 fn div(self, rhs: Vec3) -> Vec3 {
1288 (*self).div(rhs)
1289 }
1290}
1291
1292impl Mul<Vec3> for Vec3 {
1293 type Output = Self;
1294 #[inline]
1295 fn mul(self, rhs: Self) -> Self {
1296 Self {
1297 x: self.x.mul(rhs.x),
1298 y: self.y.mul(rhs.y),
1299 z: self.z.mul(rhs.z),
1300 }
1301 }
1302}
1303
1304impl Mul<&Vec3> for Vec3 {
1305 type Output = Vec3;
1306 #[inline]
1307 fn mul(self, rhs: &Vec3) -> Vec3 {
1308 self.mul(*rhs)
1309 }
1310}
1311
1312impl Mul<&Vec3> for &Vec3 {
1313 type Output = Vec3;
1314 #[inline]
1315 fn mul(self, rhs: &Vec3) -> Vec3 {
1316 (*self).mul(*rhs)
1317 }
1318}
1319
1320impl Mul<Vec3> for &Vec3 {
1321 type Output = Vec3;
1322 #[inline]
1323 fn mul(self, rhs: Vec3) -> Vec3 {
1324 (*self).mul(rhs)
1325 }
1326}
1327
1328impl MulAssign<Vec3> for Vec3 {
1329 #[inline]
1330 fn mul_assign(&mut self, rhs: Self) {
1331 self.x.mul_assign(rhs.x);
1332 self.y.mul_assign(rhs.y);
1333 self.z.mul_assign(rhs.z);
1334 }
1335}
1336
1337impl MulAssign<&Vec3> for Vec3 {
1338 #[inline]
1339 fn mul_assign(&mut self, rhs: &Vec3) {
1340 self.mul_assign(*rhs)
1341 }
1342}
1343
1344impl Mul<f32> for Vec3 {
1345 type Output = Self;
1346 #[inline]
1347 fn mul(self, rhs: f32) -> Self {
1348 Self {
1349 x: self.x.mul(rhs),
1350 y: self.y.mul(rhs),
1351 z: self.z.mul(rhs),
1352 }
1353 }
1354}
1355
1356impl Mul<&f32> for Vec3 {
1357 type Output = Vec3;
1358 #[inline]
1359 fn mul(self, rhs: &f32) -> Vec3 {
1360 self.mul(*rhs)
1361 }
1362}
1363
1364impl Mul<&f32> for &Vec3 {
1365 type Output = Vec3;
1366 #[inline]
1367 fn mul(self, rhs: &f32) -> Vec3 {
1368 (*self).mul(*rhs)
1369 }
1370}
1371
1372impl Mul<f32> for &Vec3 {
1373 type Output = Vec3;
1374 #[inline]
1375 fn mul(self, rhs: f32) -> Vec3 {
1376 (*self).mul(rhs)
1377 }
1378}
1379
1380impl MulAssign<f32> for Vec3 {
1381 #[inline]
1382 fn mul_assign(&mut self, rhs: f32) {
1383 self.x.mul_assign(rhs);
1384 self.y.mul_assign(rhs);
1385 self.z.mul_assign(rhs);
1386 }
1387}
1388
1389impl MulAssign<&f32> for Vec3 {
1390 #[inline]
1391 fn mul_assign(&mut self, rhs: &f32) {
1392 self.mul_assign(*rhs)
1393 }
1394}
1395
1396impl Mul<Vec3> for f32 {
1397 type Output = Vec3;
1398 #[inline]
1399 fn mul(self, rhs: Vec3) -> Vec3 {
1400 Vec3 {
1401 x: self.mul(rhs.x),
1402 y: self.mul(rhs.y),
1403 z: self.mul(rhs.z),
1404 }
1405 }
1406}
1407
1408impl Mul<&Vec3> for f32 {
1409 type Output = Vec3;
1410 #[inline]
1411 fn mul(self, rhs: &Vec3) -> Vec3 {
1412 self.mul(*rhs)
1413 }
1414}
1415
1416impl Mul<&Vec3> for &f32 {
1417 type Output = Vec3;
1418 #[inline]
1419 fn mul(self, rhs: &Vec3) -> Vec3 {
1420 (*self).mul(*rhs)
1421 }
1422}
1423
1424impl Mul<Vec3> for &f32 {
1425 type Output = Vec3;
1426 #[inline]
1427 fn mul(self, rhs: Vec3) -> Vec3 {
1428 (*self).mul(rhs)
1429 }
1430}
1431
1432impl Add<Vec3> for Vec3 {
1433 type Output = Self;
1434 #[inline]
1435 fn add(self, rhs: Self) -> Self {
1436 Self {
1437 x: self.x.add(rhs.x),
1438 y: self.y.add(rhs.y),
1439 z: self.z.add(rhs.z),
1440 }
1441 }
1442}
1443
1444impl Add<&Vec3> for Vec3 {
1445 type Output = Vec3;
1446 #[inline]
1447 fn add(self, rhs: &Vec3) -> Vec3 {
1448 self.add(*rhs)
1449 }
1450}
1451
1452impl Add<&Vec3> for &Vec3 {
1453 type Output = Vec3;
1454 #[inline]
1455 fn add(self, rhs: &Vec3) -> Vec3 {
1456 (*self).add(*rhs)
1457 }
1458}
1459
1460impl Add<Vec3> for &Vec3 {
1461 type Output = Vec3;
1462 #[inline]
1463 fn add(self, rhs: Vec3) -> Vec3 {
1464 (*self).add(rhs)
1465 }
1466}
1467
1468impl AddAssign<Vec3> for Vec3 {
1469 #[inline]
1470 fn add_assign(&mut self, rhs: Self) {
1471 self.x.add_assign(rhs.x);
1472 self.y.add_assign(rhs.y);
1473 self.z.add_assign(rhs.z);
1474 }
1475}
1476
1477impl AddAssign<&Vec3> for Vec3 {
1478 #[inline]
1479 fn add_assign(&mut self, rhs: &Vec3) {
1480 self.add_assign(*rhs)
1481 }
1482}
1483
1484impl Add<f32> for Vec3 {
1485 type Output = Self;
1486 #[inline]
1487 fn add(self, rhs: f32) -> Self {
1488 Self {
1489 x: self.x.add(rhs),
1490 y: self.y.add(rhs),
1491 z: self.z.add(rhs),
1492 }
1493 }
1494}
1495
1496impl Add<&f32> for Vec3 {
1497 type Output = Vec3;
1498 #[inline]
1499 fn add(self, rhs: &f32) -> Vec3 {
1500 self.add(*rhs)
1501 }
1502}
1503
1504impl Add<&f32> for &Vec3 {
1505 type Output = Vec3;
1506 #[inline]
1507 fn add(self, rhs: &f32) -> Vec3 {
1508 (*self).add(*rhs)
1509 }
1510}
1511
1512impl Add<f32> for &Vec3 {
1513 type Output = Vec3;
1514 #[inline]
1515 fn add(self, rhs: f32) -> Vec3 {
1516 (*self).add(rhs)
1517 }
1518}
1519
1520impl AddAssign<f32> for Vec3 {
1521 #[inline]
1522 fn add_assign(&mut self, rhs: f32) {
1523 self.x.add_assign(rhs);
1524 self.y.add_assign(rhs);
1525 self.z.add_assign(rhs);
1526 }
1527}
1528
1529impl AddAssign<&f32> for Vec3 {
1530 #[inline]
1531 fn add_assign(&mut self, rhs: &f32) {
1532 self.add_assign(*rhs)
1533 }
1534}
1535
1536impl Add<Vec3> for f32 {
1537 type Output = Vec3;
1538 #[inline]
1539 fn add(self, rhs: Vec3) -> Vec3 {
1540 Vec3 {
1541 x: self.add(rhs.x),
1542 y: self.add(rhs.y),
1543 z: self.add(rhs.z),
1544 }
1545 }
1546}
1547
1548impl Add<&Vec3> for f32 {
1549 type Output = Vec3;
1550 #[inline]
1551 fn add(self, rhs: &Vec3) -> Vec3 {
1552 self.add(*rhs)
1553 }
1554}
1555
1556impl Add<&Vec3> for &f32 {
1557 type Output = Vec3;
1558 #[inline]
1559 fn add(self, rhs: &Vec3) -> Vec3 {
1560 (*self).add(*rhs)
1561 }
1562}
1563
1564impl Add<Vec3> for &f32 {
1565 type Output = Vec3;
1566 #[inline]
1567 fn add(self, rhs: Vec3) -> Vec3 {
1568 (*self).add(rhs)
1569 }
1570}
1571
1572impl Sub<Vec3> for Vec3 {
1573 type Output = Self;
1574 #[inline]
1575 fn sub(self, rhs: Self) -> Self {
1576 Self {
1577 x: self.x.sub(rhs.x),
1578 y: self.y.sub(rhs.y),
1579 z: self.z.sub(rhs.z),
1580 }
1581 }
1582}
1583
1584impl Sub<&Vec3> for Vec3 {
1585 type Output = Vec3;
1586 #[inline]
1587 fn sub(self, rhs: &Vec3) -> Vec3 {
1588 self.sub(*rhs)
1589 }
1590}
1591
1592impl Sub<&Vec3> for &Vec3 {
1593 type Output = Vec3;
1594 #[inline]
1595 fn sub(self, rhs: &Vec3) -> Vec3 {
1596 (*self).sub(*rhs)
1597 }
1598}
1599
1600impl Sub<Vec3> for &Vec3 {
1601 type Output = Vec3;
1602 #[inline]
1603 fn sub(self, rhs: Vec3) -> Vec3 {
1604 (*self).sub(rhs)
1605 }
1606}
1607
1608impl SubAssign<Vec3> for Vec3 {
1609 #[inline]
1610 fn sub_assign(&mut self, rhs: Vec3) {
1611 self.x.sub_assign(rhs.x);
1612 self.y.sub_assign(rhs.y);
1613 self.z.sub_assign(rhs.z);
1614 }
1615}
1616
1617impl SubAssign<&Vec3> for Vec3 {
1618 #[inline]
1619 fn sub_assign(&mut self, rhs: &Vec3) {
1620 self.sub_assign(*rhs)
1621 }
1622}
1623
1624impl Sub<f32> for Vec3 {
1625 type Output = Self;
1626 #[inline]
1627 fn sub(self, rhs: f32) -> Self {
1628 Self {
1629 x: self.x.sub(rhs),
1630 y: self.y.sub(rhs),
1631 z: self.z.sub(rhs),
1632 }
1633 }
1634}
1635
1636impl Sub<&f32> for Vec3 {
1637 type Output = Vec3;
1638 #[inline]
1639 fn sub(self, rhs: &f32) -> Vec3 {
1640 self.sub(*rhs)
1641 }
1642}
1643
1644impl Sub<&f32> for &Vec3 {
1645 type Output = Vec3;
1646 #[inline]
1647 fn sub(self, rhs: &f32) -> Vec3 {
1648 (*self).sub(*rhs)
1649 }
1650}
1651
1652impl Sub<f32> for &Vec3 {
1653 type Output = Vec3;
1654 #[inline]
1655 fn sub(self, rhs: f32) -> Vec3 {
1656 (*self).sub(rhs)
1657 }
1658}
1659
1660impl SubAssign<f32> for Vec3 {
1661 #[inline]
1662 fn sub_assign(&mut self, rhs: f32) {
1663 self.x.sub_assign(rhs);
1664 self.y.sub_assign(rhs);
1665 self.z.sub_assign(rhs);
1666 }
1667}
1668
1669impl SubAssign<&f32> for Vec3 {
1670 #[inline]
1671 fn sub_assign(&mut self, rhs: &f32) {
1672 self.sub_assign(*rhs)
1673 }
1674}
1675
1676impl Sub<Vec3> for f32 {
1677 type Output = Vec3;
1678 #[inline]
1679 fn sub(self, rhs: Vec3) -> Vec3 {
1680 Vec3 {
1681 x: self.sub(rhs.x),
1682 y: self.sub(rhs.y),
1683 z: self.sub(rhs.z),
1684 }
1685 }
1686}
1687
1688impl Sub<&Vec3> for f32 {
1689 type Output = Vec3;
1690 #[inline]
1691 fn sub(self, rhs: &Vec3) -> Vec3 {
1692 self.sub(*rhs)
1693 }
1694}
1695
1696impl Sub<&Vec3> for &f32 {
1697 type Output = Vec3;
1698 #[inline]
1699 fn sub(self, rhs: &Vec3) -> Vec3 {
1700 (*self).sub(*rhs)
1701 }
1702}
1703
1704impl Sub<Vec3> for &f32 {
1705 type Output = Vec3;
1706 #[inline]
1707 fn sub(self, rhs: Vec3) -> Vec3 {
1708 (*self).sub(rhs)
1709 }
1710}
1711
1712impl Rem<Vec3> for Vec3 {
1713 type Output = Self;
1714 #[inline]
1715 fn rem(self, rhs: Self) -> Self {
1716 Self {
1717 x: self.x.rem(rhs.x),
1718 y: self.y.rem(rhs.y),
1719 z: self.z.rem(rhs.z),
1720 }
1721 }
1722}
1723
1724impl Rem<&Vec3> for Vec3 {
1725 type Output = Vec3;
1726 #[inline]
1727 fn rem(self, rhs: &Vec3) -> Vec3 {
1728 self.rem(*rhs)
1729 }
1730}
1731
1732impl Rem<&Vec3> for &Vec3 {
1733 type Output = Vec3;
1734 #[inline]
1735 fn rem(self, rhs: &Vec3) -> Vec3 {
1736 (*self).rem(*rhs)
1737 }
1738}
1739
1740impl Rem<Vec3> for &Vec3 {
1741 type Output = Vec3;
1742 #[inline]
1743 fn rem(self, rhs: Vec3) -> Vec3 {
1744 (*self).rem(rhs)
1745 }
1746}
1747
1748impl RemAssign<Vec3> for Vec3 {
1749 #[inline]
1750 fn rem_assign(&mut self, rhs: Self) {
1751 self.x.rem_assign(rhs.x);
1752 self.y.rem_assign(rhs.y);
1753 self.z.rem_assign(rhs.z);
1754 }
1755}
1756
1757impl RemAssign<&Vec3> for Vec3 {
1758 #[inline]
1759 fn rem_assign(&mut self, rhs: &Vec3) {
1760 self.rem_assign(*rhs)
1761 }
1762}
1763
1764impl Rem<f32> for Vec3 {
1765 type Output = Self;
1766 #[inline]
1767 fn rem(self, rhs: f32) -> Self {
1768 Self {
1769 x: self.x.rem(rhs),
1770 y: self.y.rem(rhs),
1771 z: self.z.rem(rhs),
1772 }
1773 }
1774}
1775
1776impl Rem<&f32> for Vec3 {
1777 type Output = Vec3;
1778 #[inline]
1779 fn rem(self, rhs: &f32) -> Vec3 {
1780 self.rem(*rhs)
1781 }
1782}
1783
1784impl Rem<&f32> for &Vec3 {
1785 type Output = Vec3;
1786 #[inline]
1787 fn rem(self, rhs: &f32) -> Vec3 {
1788 (*self).rem(*rhs)
1789 }
1790}
1791
1792impl Rem<f32> for &Vec3 {
1793 type Output = Vec3;
1794 #[inline]
1795 fn rem(self, rhs: f32) -> Vec3 {
1796 (*self).rem(rhs)
1797 }
1798}
1799
1800impl RemAssign<f32> for Vec3 {
1801 #[inline]
1802 fn rem_assign(&mut self, rhs: f32) {
1803 self.x.rem_assign(rhs);
1804 self.y.rem_assign(rhs);
1805 self.z.rem_assign(rhs);
1806 }
1807}
1808
1809impl RemAssign<&f32> for Vec3 {
1810 #[inline]
1811 fn rem_assign(&mut self, rhs: &f32) {
1812 self.rem_assign(*rhs)
1813 }
1814}
1815
1816impl Rem<Vec3> for f32 {
1817 type Output = Vec3;
1818 #[inline]
1819 fn rem(self, rhs: Vec3) -> Vec3 {
1820 Vec3 {
1821 x: self.rem(rhs.x),
1822 y: self.rem(rhs.y),
1823 z: self.rem(rhs.z),
1824 }
1825 }
1826}
1827
1828impl Rem<&Vec3> for f32 {
1829 type Output = Vec3;
1830 #[inline]
1831 fn rem(self, rhs: &Vec3) -> Vec3 {
1832 self.rem(*rhs)
1833 }
1834}
1835
1836impl Rem<&Vec3> for &f32 {
1837 type Output = Vec3;
1838 #[inline]
1839 fn rem(self, rhs: &Vec3) -> Vec3 {
1840 (*self).rem(*rhs)
1841 }
1842}
1843
1844impl Rem<Vec3> for &f32 {
1845 type Output = Vec3;
1846 #[inline]
1847 fn rem(self, rhs: Vec3) -> Vec3 {
1848 (*self).rem(rhs)
1849 }
1850}
1851
1852#[cfg(not(target_arch = "spirv"))]
1853impl AsRef<[f32; 3]> for Vec3 {
1854 #[inline]
1855 fn as_ref(&self) -> &[f32; 3] {
1856 unsafe { &*(self as *const Vec3 as *const [f32; 3]) }
1857 }
1858}
1859
1860#[cfg(not(target_arch = "spirv"))]
1861impl AsMut<[f32; 3]> for Vec3 {
1862 #[inline]
1863 fn as_mut(&mut self) -> &mut [f32; 3] {
1864 unsafe { &mut *(self as *mut Vec3 as *mut [f32; 3]) }
1865 }
1866}
1867
1868impl Sum for Vec3 {
1869 #[inline]
1870 fn sum<I>(iter: I) -> Self
1871 where
1872 I: Iterator<Item = Self>,
1873 {
1874 iter.fold(Self::ZERO, Self::add)
1875 }
1876}
1877
1878impl<'a> Sum<&'a Self> for Vec3 {
1879 #[inline]
1880 fn sum<I>(iter: I) -> Self
1881 where
1882 I: Iterator<Item = &'a Self>,
1883 {
1884 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
1885 }
1886}
1887
1888impl Product for Vec3 {
1889 #[inline]
1890 fn product<I>(iter: I) -> Self
1891 where
1892 I: Iterator<Item = Self>,
1893 {
1894 iter.fold(Self::ONE, Self::mul)
1895 }
1896}
1897
1898impl<'a> Product<&'a Self> for Vec3 {
1899 #[inline]
1900 fn product<I>(iter: I) -> Self
1901 where
1902 I: Iterator<Item = &'a Self>,
1903 {
1904 iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
1905 }
1906}
1907
1908impl Neg for Vec3 {
1909 type Output = Self;
1910 #[inline]
1911 fn neg(self) -> Self {
1912 Self {
1913 x: self.x.neg(),
1914 y: self.y.neg(),
1915 z: self.z.neg(),
1916 }
1917 }
1918}
1919
1920impl Neg for &Vec3 {
1921 type Output = Vec3;
1922 #[inline]
1923 fn neg(self) -> Vec3 {
1924 (*self).neg()
1925 }
1926}
1927
1928impl Index<usize> for Vec3 {
1929 type Output = f32;
1930 #[inline]
1931 fn index(&self, index: usize) -> &Self::Output {
1932 match index {
1933 0 => &self.x,
1934 1 => &self.y,
1935 2 => &self.z,
1936 _ => panic!("index out of bounds"),
1937 }
1938 }
1939}
1940
1941impl IndexMut<usize> for Vec3 {
1942 #[inline]
1943 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1944 match index {
1945 0 => &mut self.x,
1946 1 => &mut self.y,
1947 2 => &mut self.z,
1948 _ => panic!("index out of bounds"),
1949 }
1950 }
1951}
1952
1953impl fmt::Display for Vec3 {
1954 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1955 if let Some(p) = f.precision() {
1956 write!(f, "[{:.*}, {:.*}, {:.*}]", p, self.x, p, self.y, p, self.z)
1957 } else {
1958 write!(f, "[{}, {}, {}]", self.x, self.y, self.z)
1959 }
1960 }
1961}
1962
1963impl fmt::Debug for Vec3 {
1964 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1965 fmt.debug_tuple(stringify!(Vec3))
1966 .field(&self.x)
1967 .field(&self.y)
1968 .field(&self.z)
1969 .finish()
1970 }
1971}
1972
1973impl From<[f32; 3]> for Vec3 {
1974 #[inline]
1975 fn from(a: [f32; 3]) -> Self {
1976 Self::new(a[0], a[1], a[2])
1977 }
1978}
1979
1980impl From<Vec3> for [f32; 3] {
1981 #[inline]
1982 fn from(v: Vec3) -> Self {
1983 [v.x, v.y, v.z]
1984 }
1985}
1986
1987impl From<(f32, f32, f32)> for Vec3 {
1988 #[inline]
1989 fn from(t: (f32, f32, f32)) -> Self {
1990 Self::new(t.0, t.1, t.2)
1991 }
1992}
1993
1994impl From<Vec3> for (f32, f32, f32) {
1995 #[inline]
1996 fn from(v: Vec3) -> Self {
1997 (v.x, v.y, v.z)
1998 }
1999}
2000
2001impl From<(Vec2, f32)> for Vec3 {
2002 #[inline]
2003 fn from((v, z): (Vec2, f32)) -> Self {
2004 Self::new(v.x, v.y, z)
2005 }
2006}
2007
2008impl From<BVec3> for Vec3 {
2009 #[inline]
2010 fn from(v: BVec3) -> Self {
2011 Self::new(f32::from(v.x), f32::from(v.y), f32::from(v.z))
2012 }
2013}
2014
2015impl From<BVec3A> for Vec3 {
2016 #[inline]
2017 fn from(v: BVec3A) -> Self {
2018 let bool_array: [bool; 3] = v.into();
2019 Self::new(
2020 f32::from(bool_array[0]),
2021 f32::from(bool_array[1]),
2022 f32::from(bool_array[2]),
2023 )
2024 }
2025}