1use crate::{
4 Mat3, Mat3A, Mat4, Vec2, Vec3, Vec3A, Vec4,
5 euler::{EulerRot, FromEuler, ToEuler},
6 f32::math,
7 neon::*,
8};
9
10#[cfg(feature = "f64")]
11use crate::DQuat;
12
13use core::arch::aarch64::*;
14
15use core::fmt;
16use core::iter::{Product, Sum};
17use core::ops::{
18 Add, AddAssign, Deref, DerefMut, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign,
19};
20
21#[cfg(feature = "zerocopy-08")]
22use zerocopy_derive_08::*;
23
24#[repr(C)]
25union UnionCast {
26 a: [f32; 4],
27 v: Quat,
28}
29
30#[inline]
35#[must_use]
36pub const fn quat(x: f32, y: f32, z: f32, w: f32) -> Quat {
37 Quat::from_xyzw(x, y, z, w)
38}
39
40#[derive(Clone, Copy)]
50#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
51#[cfg_attr(
52 feature = "zerocopy-08",
53 derive(FromBytes, Immutable, IntoBytes, KnownLayout)
54)]
55#[repr(transparent)]
56pub struct Quat(pub(crate) float32x4_t);
57
58impl Quat {
59 const ZERO: Self = Self::from_array([0.0; 4]);
61
62 pub const IDENTITY: Self = Self::from_xyzw(0.0, 0.0, 0.0, 1.0);
64
65 pub const NAN: Self = Self::from_array([f32::NAN; 4]);
67
68 #[inline(always)]
80 #[must_use]
81 pub const fn from_xyzw(x: f32, y: f32, z: f32, w: f32) -> Self {
82 unsafe { UnionCast { a: [x, y, z, w] }.v }
83 }
84
85 #[inline]
92 #[must_use]
93 pub const fn from_array(a: [f32; 4]) -> Self {
94 Self::from_xyzw(a[0], a[1], a[2], a[3])
95 }
96
97 #[inline]
104 #[must_use]
105 pub const fn from_vec4(v: Vec4) -> Self {
106 Self(v.0)
107 }
108
109 #[inline]
120 #[must_use]
121 #[track_caller]
122 pub fn from_slice(slice: &[f32]) -> Self {
123 assert!(slice.len() >= 4);
124 Self(unsafe { vld1q_f32(slice.as_ptr()) })
125 }
126
127 #[inline]
133 #[track_caller]
134 pub fn write_to_slice(self, slice: &mut [f32]) {
135 assert!(slice.len() >= 4);
136 unsafe { vst1q_f32(slice.as_mut_ptr(), self.0) }
137 }
138
139 #[inline]
147 #[must_use]
148 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
149 pub fn from_axis_angle(axis: Vec3, angle: f32) -> Self {
150 glam_assert!(axis.is_normalized());
151 let (s, c) = math::sin_cos(angle * 0.5);
152 let v = axis * s;
153 Self::from_xyzw(v.x, v.y, v.z, c)
154 }
155
156 #[inline]
164 #[must_use]
165 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
166 pub fn from_scaled_axis(v: Vec3) -> Self {
167 let length = v.length();
168 if length == 0.0 {
169 Self::IDENTITY
170 } else {
171 Self::from_axis_angle(v / length, length)
172 }
173 }
174
175 #[inline]
177 #[must_use]
178 pub fn from_rotation_x(angle: f32) -> Self {
179 let (s, c) = math::sin_cos(angle * 0.5);
180 Self::from_xyzw(s, 0.0, 0.0, c)
181 }
182
183 #[inline]
185 #[must_use]
186 pub fn from_rotation_y(angle: f32) -> Self {
187 let (s, c) = math::sin_cos(angle * 0.5);
188 Self::from_xyzw(0.0, s, 0.0, c)
189 }
190
191 #[inline]
193 #[must_use]
194 pub fn from_rotation_z(angle: f32) -> Self {
195 let (s, c) = math::sin_cos(angle * 0.5);
196 Self::from_xyzw(0.0, 0.0, s, c)
197 }
198
199 #[inline]
201 #[must_use]
202 pub fn from_euler(euler: EulerRot, a: f32, b: f32, c: f32) -> Self {
203 Self::from_euler_angles(euler, a, b, c)
204 }
205
206 #[inline]
215 #[must_use]
216 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
217 pub fn from_rotation_axes(x_axis: Vec3, y_axis: Vec3, z_axis: Vec3) -> Self {
218 glam_assert!(x_axis.is_normalized() && y_axis.is_normalized() && z_axis.is_normalized());
219 let (m00, m01, m02) = x_axis.into();
221 let (m10, m11, m12) = y_axis.into();
222 let (m20, m21, m22) = z_axis.into();
223 if m22 <= 0.0 {
224 let dif10 = m11 - m00;
226 let omm22 = 1.0 - m22;
227 if dif10 <= 0.0 {
228 let four_xsq = omm22 - dif10;
230 let inv4x = 0.5 / math::sqrt(four_xsq);
231 Self::from_xyzw(
232 four_xsq * inv4x,
233 (m01 + m10) * inv4x,
234 (m02 + m20) * inv4x,
235 (m12 - m21) * inv4x,
236 )
237 } else {
238 let four_ysq = omm22 + dif10;
240 let inv4y = 0.5 / math::sqrt(four_ysq);
241 Self::from_xyzw(
242 (m01 + m10) * inv4y,
243 four_ysq * inv4y,
244 (m12 + m21) * inv4y,
245 (m20 - m02) * inv4y,
246 )
247 }
248 } else {
249 let sum10 = m11 + m00;
251 let opm22 = 1.0 + m22;
252 if sum10 <= 0.0 {
253 let four_zsq = opm22 - sum10;
255 let inv4z = 0.5 / math::sqrt(four_zsq);
256 Self::from_xyzw(
257 (m02 + m20) * inv4z,
258 (m12 + m21) * inv4z,
259 four_zsq * inv4z,
260 (m01 - m10) * inv4z,
261 )
262 } else {
263 let four_wsq = opm22 + sum10;
265 let inv4w = 0.5 / math::sqrt(four_wsq);
266 Self::from_xyzw(
267 (m12 - m21) * inv4w,
268 (m20 - m02) * inv4w,
269 (m01 - m10) * inv4w,
270 four_wsq * inv4w,
271 )
272 }
273 }
274 }
275
276 #[inline]
285 #[must_use]
286 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
287 pub fn from_mat3(mat: &Mat3) -> Self {
288 Self::from_rotation_axes(mat.x_axis, mat.y_axis, mat.z_axis)
289 }
290
291 #[inline]
300 #[must_use]
301 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
302 pub fn from_mat3a(mat: &Mat3A) -> Self {
303 Self::from_rotation_axes(mat.x_axis.into(), mat.y_axis.into(), mat.z_axis.into())
304 }
305
306 #[inline]
316 #[must_use]
317 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
318 pub fn from_mat4(mat: &Mat4) -> Self {
319 Self::from_rotation_axes(
320 mat.x_axis.truncate(),
321 mat.y_axis.truncate(),
322 mat.z_axis.truncate(),
323 )
324 }
325
326 #[must_use]
340 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
341 pub fn from_rotation_arc(from: Vec3, to: Vec3) -> Self {
342 glam_assert!(from.is_normalized());
343 glam_assert!(to.is_normalized());
344
345 const ONE_MINUS_EPS: f32 = 1.0 - 2.0 * f32::EPSILON;
346 let dot = from.dot(to);
347 if dot > ONE_MINUS_EPS {
348 Self::IDENTITY
350 } else if dot < -ONE_MINUS_EPS {
351 use core::f32::consts::PI; Self::from_axis_angle(from.any_orthonormal_vector(), PI)
354 } else {
355 let c = from.cross(to);
356 Self::from_xyzw(c.x, c.y, c.z, 1.0 + dot).normalize()
357 }
358 }
359
360 #[inline]
374 #[must_use]
375 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
376 pub fn from_rotation_arc_colinear(from: Vec3, to: Vec3) -> Self {
377 if from.dot(to) < 0.0 {
378 Self::from_rotation_arc(from, -to)
379 } else {
380 Self::from_rotation_arc(from, to)
381 }
382 }
383
384 #[must_use]
398 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
399 pub fn from_rotation_arc_2d(from: Vec2, to: Vec2) -> Self {
400 glam_assert!(from.is_normalized());
401 glam_assert!(to.is_normalized());
402
403 const ONE_MINUS_EPSILON: f32 = 1.0 - 2.0 * f32::EPSILON;
404 let dot = from.dot(to);
405 if dot > ONE_MINUS_EPSILON {
406 Self::IDENTITY
408 } else if dot < -ONE_MINUS_EPSILON {
409 const COS_FRAC_PI_2: f32 = 0.0;
411 const SIN_FRAC_PI_2: f32 = 1.0;
412 Self::from_xyzw(0.0, 0.0, SIN_FRAC_PI_2, COS_FRAC_PI_2)
414 } else {
415 let z = from.x * to.y - to.x * from.y;
417 let w = 1.0 + dot;
418 let len_rcp = 1.0 / math::sqrt(z * z + w * w);
420 Self::from_xyzw(0.0, 0.0, z * len_rcp, w * len_rcp)
421 }
422 }
423
424 #[inline]
426 #[must_use]
427 pub fn to_axis_angle(self) -> (Vec3, f32) {
428 const EPSILON: f32 = 1.0e-8;
429 let v = Vec3::new(self.x, self.y, self.z);
430 let length = v.length();
431 if length >= EPSILON {
432 let angle = 2.0 * math::atan2(length, self.w);
433 let axis = v / length;
434 (axis, angle)
435 } else {
436 (Vec3::X, 0.0)
437 }
438 }
439
440 #[inline]
442 #[must_use]
443 pub fn to_scaled_axis(self) -> Vec3 {
444 let (axis, angle) = self.to_axis_angle();
445 axis * angle
446 }
447
448 #[inline]
454 #[must_use]
455 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
456 pub fn to_euler(self, order: EulerRot) -> (f32, f32, f32) {
457 Mat3::from_quat(self).to_euler_angles(order)
458 }
459
460 #[inline]
462 #[must_use]
463 pub const fn to_array(&self) -> [f32; 4] {
464 unsafe { *(self as *const Self as *const [f32; 4]) }
465 }
466
467 #[inline]
469 #[must_use]
470 pub fn xyz(self) -> Vec3 {
471 Vec3::new(self.x, self.y, self.z)
472 }
473
474 #[inline]
477 #[must_use]
478 pub fn conjugate(self) -> Self {
479 const SIGN: float32x4_t = f32x4_from_array([-1.0, -1.0, -1.0, 1.0]);
480 Self(unsafe { vmulq_f32(self.0, SIGN) })
481 }
482
483 #[inline]
493 #[must_use]
494 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
495 pub fn inverse(self) -> Self {
496 glam_assert!(self.is_normalized());
497 self.conjugate()
498 }
499
500 #[inline]
503 #[must_use]
504 pub fn dot(self, rhs: Self) -> f32 {
505 Vec4::from(self).dot(Vec4::from(rhs))
506 }
507
508 #[doc(alias = "magnitude")]
510 #[inline]
511 #[must_use]
512 pub fn length(self) -> f32 {
513 Vec4::from(self).length()
514 }
515
516 #[doc(alias = "magnitude2")]
521 #[inline]
522 #[must_use]
523 pub fn length_squared(self) -> f32 {
524 Vec4::from(self).length_squared()
525 }
526
527 #[inline]
531 #[must_use]
532 pub fn length_recip(self) -> f32 {
533 Vec4::from(self).length_recip()
534 }
535
536 #[inline]
544 #[must_use]
545 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
546 pub fn normalize(self) -> Self {
547 Self::from_vec4(Vec4::from(self).normalize())
548 }
549
550 #[inline]
553 #[must_use]
554 pub fn is_finite(self) -> bool {
555 Vec4::from(self).is_finite()
556 }
557
558 #[inline]
560 #[must_use]
561 pub fn is_nan(self) -> bool {
562 Vec4::from(self).is_nan()
563 }
564
565 #[inline]
569 #[must_use]
570 pub fn is_normalized(self) -> bool {
571 Vec4::from(self).is_normalized()
572 }
573
574 #[inline]
576 #[must_use]
577 pub fn is_near_identity(self) -> bool {
578 const THRESHOLD: f32 = 1.0 - 1e-6;
583 self.w.abs() > THRESHOLD
584 }
585
586 #[inline]
595 #[must_use]
596 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
597 pub fn angle_between(self, rhs: Self) -> f32 {
598 glam_assert!(self.is_normalized() && rhs.is_normalized());
599 math::acos_approx(self.dot(rhs).abs()) * 2.0
600 }
601
602 #[inline]
614 #[must_use]
615 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
616 pub fn rotate_towards(self, rhs: Self, max_angle: f32) -> Self {
617 glam_assert!(self.is_normalized() && rhs.is_normalized());
618 let angle = self.angle_between(rhs);
619 if angle <= 1e-4 {
620 return rhs;
621 }
622 if max_angle < 0.0 {
623 let target = (self - rhs * self.dot(rhs)).normalize();
625 let angle = self.angle_between(target);
626 if angle <= 1e-4 {
627 return target;
628 }
629 return self.slerp(target, (-max_angle / angle).clamp(0.0, 1.0));
630 }
631 self.slerp(rhs, (max_angle / angle).clamp(0.0, 1.0))
632 }
633
634 #[inline]
644 #[must_use]
645 pub fn abs_diff_eq(self, rhs: Self, max_abs_diff: f32) -> bool {
646 Vec4::from(self).abs_diff_eq(Vec4::from(rhs), max_abs_diff)
647 }
648
649 #[inline(always)]
650 #[must_use]
651 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
652 fn lerp_impl(self, end: Self, s: f32) -> Self {
653 (self * (1.0 - s) + end * s).normalize()
654 }
655
656 #[doc(alias = "mix")]
669 #[inline]
670 #[must_use]
671 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
672 pub fn lerp(self, end: Self, s: f32) -> Self {
673 glam_assert!(self.is_normalized());
674 glam_assert!(end.is_normalized());
675
676 const NEG_ZERO: float32x4_t = f32x4_from_array([-0.0; 4]);
677 unsafe {
678 let dot = dot4_into_f32x4(self.0, end.0);
679 let bias = vandq_u32(vreinterpretq_u32_f32(dot), vreinterpretq_u32_f32(NEG_ZERO));
682 self.lerp_impl(
683 Self(vreinterpretq_f32_u32(veorq_u32(
684 vreinterpretq_u32_f32(end.0),
685 bias,
686 ))),
687 s,
688 )
689 }
690 }
691
692 #[inline(always)]
693 #[must_use]
694 fn slerp_impl(self, end: Self, dot: f32, s: f32) -> Self {
695 let theta = math::acos_approx(dot);
696
697 let coefs = [1.0 - s, s, 1.0, 0.0];
698 unsafe {
699 let tmp = vmulq_f32(vdupq_n_f32(theta), vld1q_f32(coefs.as_ptr()));
700 let tmp = f32x4_sin(tmp);
701
702 let scale1 = vdupq_n_f32(vgetq_lane_f32(tmp, 0));
703 let scale2 = vdupq_n_f32(vgetq_lane_f32(tmp, 1));
704 let theta_sin = vdupq_n_f32(vgetq_lane_f32(tmp, 2));
705
706 Self(vdivq_f32(
707 vfmaq_f32(vmulq_f32(self.0, scale1), end.0, scale2),
708 theta_sin,
709 ))
710 }
711 }
712
713 #[inline]
723 #[must_use]
724 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
725 pub fn slerp(self, mut end: Self, s: f32) -> Self {
726 glam_assert!(self.is_normalized());
728 glam_assert!(end.is_normalized());
729
730 let mut dot = self.dot(end);
737 if dot < 0.0 {
738 end = -end;
739 dot = -dot;
740 }
741
742 const DOT_THRESHOLD: f32 = 1.0 - f32::EPSILON;
743 if dot > DOT_THRESHOLD {
744 self.lerp_impl(end, s)
746 } else {
747 self.slerp_impl(end, dot, s)
748 }
749 }
750
751 #[inline]
765 #[must_use]
766 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
767 pub fn slerp_long(self, end: Self, s: f32) -> Self {
768 glam_assert!(self.is_normalized());
769 glam_assert!(end.is_normalized());
770
771 let dot = self.dot(end);
772
773 const DOT_THRESHOLD: f32 = 1.0 - f32::EPSILON;
774 if dot.abs() > DOT_THRESHOLD {
775 self.lerp_impl(end, s)
777 } else {
778 self.slerp_impl(end, dot, s)
779 }
780 }
781
782 #[inline]
788 #[must_use]
789 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
790 pub fn mul_vec3(self, rhs: Vec3) -> Vec3 {
791 glam_assert!(self.is_normalized());
792
793 self.mul_vec3a(rhs.into()).into()
794 }
795
796 #[inline]
801 #[must_use]
802 pub fn mul_quat(self, rhs: Self) -> Self {
803 unsafe {
804 let lhs = self.0;
805 let rhs = rhs.0;
806
807 const CONTROL_WZYX: float32x4_t = f32x4_from_array([1.0, -1.0, 1.0, -1.0]);
808 const CONTROL_ZWXY: float32x4_t = f32x4_from_array([1.0, 1.0, -1.0, -1.0]);
809 const CONTROL_YXWZ: float32x4_t = f32x4_from_array([-1.0, 1.0, 1.0, -1.0]);
810
811 let r_xxxx = vdupq_laneq_f32(lhs, 0);
812 let r_yyyy = vdupq_laneq_f32(lhs, 1);
813 let r_zzzz = vdupq_laneq_f32(lhs, 2);
814 let r_wwww = vdupq_laneq_f32(lhs, 3);
815
816 let lxrw_lyrw_lzrw_lwrw = vmulq_f32(r_wwww, rhs);
817 let l_wzyx = vrev64q_f32(rhs);
819 let l_wzyx = vextq_f32(l_wzyx, l_wzyx, 2);
820
821 let lwrx_lzrx_lyrx_lxrx = vmulq_f32(r_xxxx, l_wzyx);
822 let l_zwxy = vrev64q_f32(l_wzyx);
824
825 let lzry_lwry_lxry_lyry = vmulq_f32(r_yyyy, l_zwxy);
826 let l_yxwz = vrev64q_f32(l_zwxy);
828 let l_yxwz = vextq_f32(l_yxwz, l_yxwz, 2);
829
830 let lzry_lwry_nlxry_nlyry = vmulq_f32(lzry_lwry_lxry_lyry, CONTROL_ZWXY);
831
832 let lyrz_lxrz_lwrz_lzrz = vmulq_f32(r_zzzz, l_yxwz);
833 let result0 = vfmaq_f32(lxrw_lyrw_lzrw_lwrw, lwrx_lzrx_lyrx_lxrx, CONTROL_WZYX);
834
835 let result1 = vfmaq_f32(lzry_lwry_nlxry_nlyry, lyrz_lxrz_lwrz_lzrz, CONTROL_YXWZ);
836 Self(vaddq_f32(result0, result1))
837 }
838 }
839
840 #[inline]
850 #[must_use]
851 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
852 pub fn from_affine3(a: &crate::Affine3) -> Self {
853 Self::from_rotation_axes(a.matrix3.x_axis, a.matrix3.y_axis, a.matrix3.z_axis)
854 }
855
856 #[inline]
866 #[must_use]
867 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
868 pub fn from_affine3a(a: &crate::Affine3A) -> Self {
869 Self::from_rotation_axes(
870 a.matrix3.x_axis.into(),
871 a.matrix3.y_axis.into(),
872 a.matrix3.z_axis.into(),
873 )
874 }
875
876 #[inline]
882 #[must_use]
883 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
884 pub fn mul_vec3a(self, rhs: Vec3A) -> Vec3A {
885 glam_assert!(self.is_normalized());
886
887 unsafe {
888 let w = self.w;
889 let b = Vec3A::from(self.0);
890 let b2 = b.length_squared();
891 Vec3A(vaddq_f32(
892 vaddq_f32(
893 vmulq_n_f32(rhs.0, (w * w) - b2),
894 vmulq_n_f32(b.0, rhs.dot(b) * 2.0),
895 ),
896 vmulq_n_f32(b.cross(rhs).0, w * 2.0),
897 ))
898 }
899 }
900
901 #[cfg(feature = "f64")]
902 #[inline]
903 #[must_use]
904 pub fn as_dquat(self) -> DQuat {
905 DQuat::from_xyzw(self.x as f64, self.y as f64, self.z as f64, self.w as f64)
906 }
907}
908
909impl fmt::Debug for Quat {
910 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
911 fmt.debug_tuple(stringify!(Quat))
912 .field(&self.x)
913 .field(&self.y)
914 .field(&self.z)
915 .field(&self.w)
916 .finish()
917 }
918}
919
920impl fmt::Display for Quat {
921 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
922 if let Some(p) = f.precision() {
923 write!(
924 f,
925 "[{:.*}, {:.*}, {:.*}, {:.*}]",
926 p, self.x, p, self.y, p, self.z, p, self.w
927 )
928 } else {
929 write!(f, "[{}, {}, {}, {}]", self.x, self.y, self.z, self.w)
930 }
931 }
932}
933
934impl Add for Quat {
935 type Output = Self;
936 #[inline]
943 fn add(self, rhs: Self) -> Self {
944 Self::from_vec4(Vec4::from(self) + Vec4::from(rhs))
945 }
946}
947
948impl Add<&Self> for Quat {
949 type Output = Self;
950 #[inline]
951 fn add(self, rhs: &Self) -> Self {
952 self.add(*rhs)
953 }
954}
955
956impl Add<&Quat> for &Quat {
957 type Output = Quat;
958 #[inline]
959 fn add(self, rhs: &Quat) -> Quat {
960 (*self).add(*rhs)
961 }
962}
963
964impl Add<Quat> for &Quat {
965 type Output = Quat;
966 #[inline]
967 fn add(self, rhs: Quat) -> Quat {
968 (*self).add(rhs)
969 }
970}
971
972impl AddAssign for Quat {
973 #[inline]
974 fn add_assign(&mut self, rhs: Self) {
975 *self = self.add(rhs);
976 }
977}
978
979impl AddAssign<&Self> for Quat {
980 #[inline]
981 fn add_assign(&mut self, rhs: &Self) {
982 self.add_assign(*rhs);
983 }
984}
985
986impl Sub for Quat {
987 type Output = Self;
988 #[inline]
992 fn sub(self, rhs: Self) -> Self {
993 Self::from_vec4(Vec4::from(self) - Vec4::from(rhs))
994 }
995}
996
997impl Sub<&Self> for Quat {
998 type Output = Self;
999 #[inline]
1000 fn sub(self, rhs: &Self) -> Self {
1001 self.sub(*rhs)
1002 }
1003}
1004
1005impl Sub<&Quat> for &Quat {
1006 type Output = Quat;
1007 #[inline]
1008 fn sub(self, rhs: &Quat) -> Quat {
1009 (*self).sub(*rhs)
1010 }
1011}
1012
1013impl Sub<Quat> for &Quat {
1014 type Output = Quat;
1015 #[inline]
1016 fn sub(self, rhs: Quat) -> Quat {
1017 (*self).sub(rhs)
1018 }
1019}
1020
1021impl SubAssign for Quat {
1022 #[inline]
1023 fn sub_assign(&mut self, rhs: Self) {
1024 *self = self.sub(rhs);
1025 }
1026}
1027
1028impl SubAssign<&Self> for Quat {
1029 #[inline]
1030 fn sub_assign(&mut self, rhs: &Self) {
1031 self.sub_assign(*rhs);
1032 }
1033}
1034
1035impl Mul<f32> for Quat {
1036 type Output = Self;
1037 #[inline]
1041 fn mul(self, rhs: f32) -> Self {
1042 Self::from_vec4(Vec4::from(self) * rhs)
1043 }
1044}
1045
1046impl Mul<&f32> for Quat {
1047 type Output = Self;
1048 #[inline]
1049 fn mul(self, rhs: &f32) -> Self {
1050 self.mul(*rhs)
1051 }
1052}
1053
1054impl Mul<&f32> for &Quat {
1055 type Output = Quat;
1056 #[inline]
1057 fn mul(self, rhs: &f32) -> Quat {
1058 (*self).mul(*rhs)
1059 }
1060}
1061
1062impl Mul<f32> for &Quat {
1063 type Output = Quat;
1064 #[inline]
1065 fn mul(self, rhs: f32) -> Quat {
1066 (*self).mul(rhs)
1067 }
1068}
1069
1070impl MulAssign<f32> for Quat {
1071 #[inline]
1072 fn mul_assign(&mut self, rhs: f32) {
1073 *self = self.mul(rhs);
1074 }
1075}
1076
1077impl MulAssign<&f32> for Quat {
1078 #[inline]
1079 fn mul_assign(&mut self, rhs: &f32) {
1080 self.mul_assign(*rhs);
1081 }
1082}
1083
1084impl Div<f32> for Quat {
1085 type Output = Self;
1086 #[inline]
1089 fn div(self, rhs: f32) -> Self {
1090 Self::from_vec4(Vec4::from(self) / rhs)
1091 }
1092}
1093
1094impl Div<&f32> for Quat {
1095 type Output = Self;
1096 #[inline]
1097 fn div(self, rhs: &f32) -> Self {
1098 self.div(*rhs)
1099 }
1100}
1101
1102impl Div<&f32> for &Quat {
1103 type Output = Quat;
1104 #[inline]
1105 fn div(self, rhs: &f32) -> Quat {
1106 (*self).div(*rhs)
1107 }
1108}
1109
1110impl Div<f32> for &Quat {
1111 type Output = Quat;
1112 #[inline]
1113 fn div(self, rhs: f32) -> Quat {
1114 (*self).div(rhs)
1115 }
1116}
1117
1118impl DivAssign<f32> for Quat {
1119 #[inline]
1120 fn div_assign(&mut self, rhs: f32) {
1121 *self = self.div(rhs);
1122 }
1123}
1124
1125impl DivAssign<&f32> for Quat {
1126 #[inline]
1127 fn div_assign(&mut self, rhs: &f32) {
1128 self.div_assign(*rhs);
1129 }
1130}
1131
1132impl Mul for Quat {
1133 type Output = Self;
1134 #[inline]
1140 fn mul(self, rhs: Self) -> Self {
1141 self.mul_quat(rhs)
1142 }
1143}
1144
1145impl Mul<&Self> for Quat {
1146 type Output = Self;
1147 #[inline]
1148 fn mul(self, rhs: &Self) -> Self {
1149 self.mul(*rhs)
1150 }
1151}
1152
1153impl Mul<&Quat> for &Quat {
1154 type Output = Quat;
1155 #[inline]
1156 fn mul(self, rhs: &Quat) -> Quat {
1157 (*self).mul(*rhs)
1158 }
1159}
1160
1161impl Mul<Quat> for &Quat {
1162 type Output = Quat;
1163 #[inline]
1164 fn mul(self, rhs: Quat) -> Quat {
1165 (*self).mul(rhs)
1166 }
1167}
1168
1169impl MulAssign for Quat {
1170 #[inline]
1171 fn mul_assign(&mut self, rhs: Self) {
1172 *self = self.mul(rhs);
1173 }
1174}
1175
1176impl MulAssign<&Self> for Quat {
1177 #[inline]
1178 fn mul_assign(&mut self, rhs: &Self) {
1179 self.mul_assign(*rhs);
1180 }
1181}
1182
1183impl Mul<Vec3> for Quat {
1184 type Output = Vec3;
1185 #[inline]
1191 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
1192 fn mul(self, rhs: Vec3) -> Self::Output {
1193 self.mul_vec3(rhs)
1194 }
1195}
1196
1197impl Mul<&Vec3> for Quat {
1198 type Output = Vec3;
1199 #[inline]
1200 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
1201 fn mul(self, rhs: &Vec3) -> Vec3 {
1202 self.mul(*rhs)
1203 }
1204}
1205
1206impl Mul<&Vec3> for &Quat {
1207 type Output = Vec3;
1208 #[inline]
1209 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
1210 fn mul(self, rhs: &Vec3) -> Vec3 {
1211 (*self).mul(*rhs)
1212 }
1213}
1214
1215impl Mul<Vec3> for &Quat {
1216 type Output = Vec3;
1217 #[inline]
1218 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
1219 fn mul(self, rhs: Vec3) -> Vec3 {
1220 (*self).mul(rhs)
1221 }
1222}
1223
1224impl Mul<Vec3A> for Quat {
1225 type Output = Vec3A;
1226 #[inline]
1232 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
1233 fn mul(self, rhs: Vec3A) -> Self::Output {
1234 self.mul_vec3a(rhs)
1235 }
1236}
1237
1238impl Mul<&Vec3A> for Quat {
1239 type Output = Vec3A;
1240 #[inline]
1241 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
1242 fn mul(self, rhs: &Vec3A) -> Vec3A {
1243 self.mul(*rhs)
1244 }
1245}
1246
1247impl Mul<&Vec3A> for &Quat {
1248 type Output = Vec3A;
1249 #[inline]
1250 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
1251 fn mul(self, rhs: &Vec3A) -> Vec3A {
1252 (*self).mul(*rhs)
1253 }
1254}
1255
1256impl Mul<Vec3A> for &Quat {
1257 type Output = Vec3A;
1258 #[inline]
1259 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
1260 fn mul(self, rhs: Vec3A) -> Vec3A {
1261 (*self).mul(rhs)
1262 }
1263}
1264
1265impl Neg for Quat {
1266 type Output = Self;
1267 #[inline]
1268 fn neg(self) -> Self {
1269 self * -1.0
1270 }
1271}
1272
1273impl Neg for &Quat {
1274 type Output = Quat;
1275 #[inline]
1276 fn neg(self) -> Quat {
1277 (*self).neg()
1278 }
1279}
1280
1281impl Default for Quat {
1282 #[inline]
1283 fn default() -> Self {
1284 Self::IDENTITY
1285 }
1286}
1287
1288impl PartialEq for Quat {
1289 #[inline]
1290 fn eq(&self, rhs: &Self) -> bool {
1291 Vec4::from(*self).eq(&Vec4::from(*rhs))
1292 }
1293}
1294
1295impl AsRef<[f32; 4]> for Quat {
1296 #[inline]
1297 fn as_ref(&self) -> &[f32; 4] {
1298 unsafe { &*(self as *const Self as *const [f32; 4]) }
1299 }
1300}
1301
1302impl Sum<Self> for Quat {
1303 fn sum<I>(iter: I) -> Self
1304 where
1305 I: Iterator<Item = Self>,
1306 {
1307 iter.fold(Self::ZERO, Self::add)
1308 }
1309}
1310
1311impl<'a> Sum<&'a Self> for Quat {
1312 fn sum<I>(iter: I) -> Self
1313 where
1314 I: Iterator<Item = &'a Self>,
1315 {
1316 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
1317 }
1318}
1319
1320impl Product for Quat {
1321 fn product<I>(iter: I) -> Self
1322 where
1323 I: Iterator<Item = Self>,
1324 {
1325 iter.fold(Self::IDENTITY, Self::mul)
1326 }
1327}
1328
1329impl<'a> Product<&'a Self> for Quat {
1330 fn product<I>(iter: I) -> Self
1331 where
1332 I: Iterator<Item = &'a Self>,
1333 {
1334 iter.fold(Self::IDENTITY, |a, &b| Self::mul(a, b))
1335 }
1336}
1337
1338impl From<Quat> for Vec4 {
1339 #[inline]
1340 fn from(q: Quat) -> Self {
1341 Self(q.0)
1342 }
1343}
1344
1345impl From<Quat> for (f32, f32, f32, f32) {
1346 #[inline]
1347 fn from(q: Quat) -> Self {
1348 Vec4::from(q).into()
1349 }
1350}
1351
1352impl From<Quat> for [f32; 4] {
1353 #[inline]
1354 fn from(q: Quat) -> Self {
1355 Vec4::from(q).into()
1356 }
1357}
1358
1359impl From<Quat> for float32x4_t {
1360 #[inline]
1361 fn from(q: Quat) -> Self {
1362 q.0
1363 }
1364}
1365
1366impl Deref for Quat {
1367 type Target = crate::deref::Vec4<f32>;
1368 #[inline]
1369 fn deref(&self) -> &Self::Target {
1370 unsafe { &*(self as *const Self).cast() }
1371 }
1372}
1373
1374impl DerefMut for Quat {
1375 #[inline]
1376 fn deref_mut(&mut self) -> &mut Self::Target {
1377 unsafe { &mut *(self as *mut Self).cast() }
1378 }
1379}