1#![deny(warnings)]
16
17use glam_det as glam;
18
19#[cfg(feature = "f64")]
20pub type Real = f64;
21#[cfg(not(feature = "f64"))]
22pub type Real = f32;
23
24mod na {
25 use crate::Real;
26
27 pub type Vec3 = nalgebra::Vector3<Real>;
28 pub type Point3 = nalgebra::Point3<Real>;
29 pub type UnitVec3 = nalgebra::UnitVector3<Real>;
30 pub type UnitQuat = nalgebra::UnitQuaternion<Real>;
31 pub type Isometry3 = nalgebra::Isometry3<Real>;
32 pub type Quat = nalgebra::Quaternion<Real>;
33 pub type Translation3 = nalgebra::Translation3<Real>;
34 pub type Mat3 = nalgebra::Matrix3<Real>;
35}
36
37pub trait ConvTo<T> {
38 fn conv_to(self) -> T;
39}
40
41impl ConvTo<glam::Point3> for na::Point3 {
42 #[inline]
43 fn conv_to(self) -> glam::Point3 {
44 glam::Point3::new(self.x, self.y, self.z)
45 }
46}
47
48impl ConvTo<na::Point3> for glam::Point3 {
49 #[inline]
50 fn conv_to(self) -> na::Point3 {
51 na::Point3::new(self.x, self.y, self.z)
52 }
53}
54
55impl ConvTo<glam::UnitVec3> for na::UnitVec3 {
56 #[inline]
57 fn conv_to(self) -> glam::UnitVec3 {
58 glam::UnitVec3::new_unchecked(self.x, self.y, self.z)
59 }
60}
61
62impl ConvTo<na::UnitVec3> for glam::UnitVec3 {
63 #[inline]
64 fn conv_to(self) -> na::UnitVec3 {
65 na::UnitVec3::new_unchecked(na::Vec3::new(self.x, self.y, self.z))
66 }
67}
68
69impl ConvTo<glam::Vec3> for na::Vec3 {
70 #[inline]
71 fn conv_to(self) -> glam::Vec3 {
72 glam::Vec3::new(self.x, self.y, self.z)
73 }
74}
75
76impl ConvTo<na::Vec3> for glam::Vec3 {
77 #[inline]
78 fn conv_to(self) -> na::Vec3 {
79 na::Vec3::new(self.x, self.y, self.z)
80 }
81}
82
83impl ConvTo<glam::UnitQuat> for na::UnitQuat {
84 #[inline]
85 fn conv_to(self) -> glam::UnitQuat {
86 glam::UnitQuat::from_xyzw_unchecked(self.i, self.j, self.k, self.w)
87 }
88}
89
90impl ConvTo<na::UnitQuat> for glam::UnitQuat {
91 #[inline]
92 fn conv_to(self) -> na::UnitQuat {
93 let vec = na::Vec3::new(self.x, self.y, self.z);
94 na::UnitQuat::new_normalize(na::Quat::from_parts(self.w, vec))
95 }
96}
97
98impl ConvTo<glam::Isometry3> for na::Isometry3 {
99 #[inline]
100 fn conv_to(self) -> glam::Isometry3 {
101 glam::Isometry3::from_rotation_translation(
102 self.rotation.conv_to(),
103 self.translation.vector.conv_to(),
104 )
105 }
106}
107
108impl ConvTo<na::Isometry3> for glam::Isometry3 {
109 #[inline]
110 fn conv_to(self) -> na::Isometry3 {
111 na::Isometry3::from_parts(
112 na::Translation3::from(self.translation.conv_to()),
113 self.rotation.conv_to(),
114 )
115 }
116}
117
118impl ConvTo<glam::Mat3> for na::Mat3 {
119 #[inline]
120 fn conv_to(self) -> glam::Mat3 {
121 glam::Mat3::from_cols_array_2d(&self.data.0)
122 }
123}