Skip to content

Commit 4af979c

Browse files
committed
Support multiple version of the optional glam conversion
1 parent ef3257b commit 4af979c

File tree

14 files changed

+158
-28
lines changed

14 files changed

+158
-28
lines changed

Cargo.toml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ macros = [ "nalgebra-macros" ]
3636

3737
# Conversion
3838
convert-mint = [ "mint" ]
39-
convert-glam = [ "glam" ]
40-
convert-glam-unchecked = [ "convert-glam" ] # Enable edgy conversions like Mat4 -> Isometry3
4139
convert-bytemuck = [ "bytemuck" ]
40+
convert-glam013 = [ "glam013" ]
41+
convert-glam013-unchecked = [ "convert-glam013" ] # Enable edgy conversions like Mat4 -> Isometry3
42+
convert-glam014 = [ "glam014" ]
43+
convert-glam014-unchecked = [ "convert-glam014" ] # Enable edgy conversions like Mat4 -> Isometry3
44+
convert-glam015 = [ "glam015" ]
45+
convert-glam015-unchecked = [ "convert-glam015" ] # Enable edgy conversions like Mat4 -> Isometry3
4246

4347
# Serialization
4448
## To use serde in a #[no-std] environment, enable the
@@ -78,13 +82,16 @@ serde = { version = "1.0", default-features = false, features = [ "deri
7882
abomonation = { version = "0.7", optional = true }
7983
rkyv = { version = "~0.6.4", default-features = false, features = ["const_generics"], optional = true }
8084
mint = { version = "0.5", optional = true }
81-
glam = { version = "0.13", optional = true }
8285
quickcheck = { version = "1", optional = true }
8386
pest = { version = "2", optional = true }
8487
pest_derive = { version = "2", optional = true }
8588
bytemuck = { version = "1.5", optional = true }
8689
matrixcompare-core = { version = "0.1", optional = true }
8790
proptest = { version = "1", optional = true, default-features = false, features = ["std"] }
91+
glam013 = { package = "glam", version = "0.13", optional = true }
92+
glam014 = { package = "glam", version = "0.14", optional = true }
93+
glam015 = { package = "glam", version = "0.15", optional = true }
94+
8895

8996
[dev-dependencies]
9097
serde_json = "1.0"

src/third_party/glam/glam_isometry.rs renamed to src/third_party/glam/common/glam_isometry.rs

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use super::glam::{DMat3, DMat4, DQuat, DVec3, Mat3, Mat4, Quat, Vec3};
12
use crate::{Isometry2, Isometry3};
2-
use glam::{DMat3, DMat4, DQuat, DVec3, Mat3, Mat4, Quat, Vec3};
33

44
impl From<Isometry2<f32>> for Mat3 {
55
fn from(iso: Isometry2<f32>) -> Mat3 {
@@ -53,8 +53,8 @@ impl From<Isometry2<f64>> for (DVec3, DQuat) {
5353

5454
#[cfg(feature = "convert-glam-unchecked")]
5555
mod unchecked {
56+
use super::super::glam::{DMat3, DMat4, DQuat, DVec2, DVec3, Mat3, Mat4, Quat, Vec2, Vec3};
5657
use crate::{Isometry2, Isometry3, Matrix3, Matrix4};
57-
use glam::{DMat3, DMat4, DQuat, DVec2, DVec3, Mat3, Mat4, Quat, Vec2, Vec3};
5858

5959
impl From<(Vec3, Quat)> for Isometry3<f32> {
6060
fn from((tra, rot): (Vec3, Quat)) -> Self {
@@ -92,6 +92,78 @@ mod unchecked {
9292
}
9393
}
9494

95+
impl From<(Vec2, f32)> for Isometry2<f32> {
96+
fn from((tra, rot): (Vec2, f32)) -> Self {
97+
Isometry2::new([tra.x, tra.y].into(), rot)
98+
}
99+
}
100+
101+
impl From<(DVec2, f64)> for Isometry2<f64> {
102+
fn from((tra, rot): (DVec2, f64)) -> Self {
103+
Isometry2::new([tra.x, tra.y].into(), rot)
104+
}
105+
}
106+
107+
impl From<Quat> for Isometry3<f32> {
108+
fn from(rot: Quat) -> Self {
109+
Isometry3::from_parts(crate::one(), rot.into())
110+
}
111+
}
112+
113+
impl From<DQuat> for Isometry3<f64> {
114+
fn from(rot: DQuat) -> Self {
115+
Isometry3::from_parts(crate::one(), rot.into())
116+
}
117+
}
118+
119+
impl From<Quat> for Isometry2<f32> {
120+
fn from(rot: Quat) -> Self {
121+
Isometry2::new(crate::zero(), rot.to_axis_angle().1)
122+
}
123+
}
124+
125+
impl From<DQuat> for Isometry2<f64> {
126+
fn from(rot: DQuat) -> Self {
127+
Isometry2::new(crate::zero(), rot.to_axis_angle().1)
128+
}
129+
}
130+
131+
impl From<Vec3> for Isometry3<f32> {
132+
fn from(tra: Vec3) -> Self {
133+
Isometry3::from_parts(tra.into(), crate::one())
134+
}
135+
}
136+
137+
impl From<DVec3> for Isometry3<f64> {
138+
fn from(tra: DVec3) -> Self {
139+
Isometry3::from_parts(tra.into(), crate::one())
140+
}
141+
}
142+
143+
impl From<Vec2> for Isometry2<f32> {
144+
fn from(tra: Vec2) -> Self {
145+
Isometry2::new(tra.into(), crate::one())
146+
}
147+
}
148+
149+
impl From<DVec2> for Isometry2<f64> {
150+
fn from(tra: DVec2) -> Self {
151+
Isometry2::new(tra.into(), crate::one())
152+
}
153+
}
154+
155+
impl From<Vec3> for Isometry2<f32> {
156+
fn from(tra: Vec3) -> Self {
157+
Isometry2::new([tra.x, tra.y].into(), crate::one())
158+
}
159+
}
160+
161+
impl From<DVec3> for Isometry2<f64> {
162+
fn from(tra: DVec3) -> Self {
163+
Isometry2::new([tra.x, tra.y].into(), crate::one())
164+
}
165+
}
166+
95167
impl From<Mat3> for Isometry2<f32> {
96168
fn from(mat3: Mat3) -> Isometry2<f32> {
97169
crate::convert_unchecked(Matrix3::from(mat3))

src/third_party/glam/glam_matrix.rs renamed to src/third_party/glam/common/glam_matrix.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use crate::storage::Storage;
2-
use crate::{Matrix, Matrix2, Matrix3, Matrix4, Vector, Vector2, Vector3, Vector4, U2, U3, U4};
3-
use glam::{
1+
use super::glam::{
42
BVec2, BVec3, BVec4, DMat2, DMat3, DMat4, DVec2, DVec3, DVec4, IVec2, IVec3, IVec4, Mat2, Mat3,
53
Mat4, UVec2, UVec3, UVec4, Vec2, Vec3, Vec3A, Vec4,
64
};
5+
use crate::storage::Storage;
6+
use crate::{Matrix, Matrix2, Matrix3, Matrix4, Vector, Vector2, Vector3, Vector4, U2, U3, U4};
77

88
macro_rules! impl_vec_conversion(
99
($N: ty, $Vec2: ty, $Vec3: ty, $Vec4: ty) => {

src/third_party/glam/glam_point.rs renamed to src/third_party/glam/common/glam_point.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use crate::{Point2, Point3, Point4};
2-
use glam::{
1+
use super::glam::{
32
BVec2, BVec3, BVec4, DVec2, DVec3, DVec4, IVec2, IVec3, IVec4, UVec2, UVec3, UVec4, Vec2, Vec3,
43
Vec3A, Vec4,
54
};
5+
use crate::{Point2, Point3, Point4};
66

77
macro_rules! impl_point_conversion(
88
($N: ty, $Vec2: ty, $Vec3: ty, $Vec4: ty) => {

src/third_party/glam/glam_quaternion.rs renamed to src/third_party/glam/common/glam_quaternion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use super::glam::{DQuat, Quat};
12
use crate::{Quaternion, UnitQuaternion};
2-
use glam::{DQuat, Quat};
33

44
impl From<Quat> for Quaternion<f32> {
55
#[inline]
@@ -45,8 +45,8 @@ impl From<UnitQuaternion<f64>> for DQuat {
4545

4646
#[cfg(feature = "convert-glam-unchecked")]
4747
mod unchecked {
48+
use super::super::glam::{DQuat, Quat};
4849
use crate::{Quaternion, UnitQuaternion};
49-
use glam::{DQuat, Quat};
5050

5151
impl From<Quat> for UnitQuaternion<f32> {
5252
#[inline]

src/third_party/glam/glam_rotation.rs renamed to src/third_party/glam/common/glam_rotation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use super::glam::{DMat2, DQuat, Mat2, Quat};
12
use crate::{Rotation2, Rotation3, UnitQuaternion};
2-
use glam::{DMat2, DQuat, Mat2, Quat};
33

44
impl From<Rotation2<f32>> for Mat2 {
55
#[inline]
@@ -31,8 +31,8 @@ impl From<Rotation3<f64>> for DQuat {
3131

3232
#[cfg(feature = "convert-glam-unchecked")]
3333
mod unchecked {
34+
use super::super::glam::{DMat2, DQuat, Mat2, Quat};
3435
use crate::{Rotation2, Rotation3, UnitQuaternion};
35-
use glam::{DMat2, DQuat, Mat2, Quat};
3636

3737
impl From<Mat2> for Rotation2<f32> {
3838
#[inline]

src/third_party/glam/glam_similarity.rs renamed to src/third_party/glam/common/glam_similarity.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use super::glam::{DMat3, DMat4, Mat3, Mat4};
12
use crate::{Similarity2, Similarity3};
2-
use glam::{DMat3, DMat4, Mat3, Mat4};
33

44
impl From<Similarity2<f32>> for Mat3 {
55
fn from(iso: Similarity2<f32>) -> Mat3 {
@@ -25,8 +25,8 @@ impl From<Similarity3<f64>> for DMat4 {
2525

2626
#[cfg(feature = "convert-glam-unchecked")]
2727
mod unchecked {
28+
use super::super::glam::{DMat3, DMat4, Mat3, Mat4};
2829
use crate::{Matrix3, Matrix4, Similarity2, Similarity3};
29-
use glam::{DMat3, DMat4, Mat3, Mat4};
3030

3131
impl From<Mat3> for Similarity2<f32> {
3232
fn from(mat3: Mat3) -> Similarity2<f32> {

src/third_party/glam/glam_translation.rs renamed to src/third_party/glam/common/glam_translation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use super::glam::{DVec2, DVec3, DVec4, Vec2, Vec3, Vec3A, Vec4};
12
use crate::{Translation2, Translation3, Translation4};
2-
use glam::{DVec2, DVec3, DVec4, Vec2, Vec3, Vec3A, Vec4};
33

44
macro_rules! impl_translation_conversion(
55
($N: ty, $Vec2: ty, $Vec3: ty, $Vec4: ty) => {

src/third_party/glam/glam_unit_complex.rs renamed to src/third_party/glam/common/glam_unit_complex.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use super::glam::{DMat2, Mat2};
12
use crate::UnitComplex;
2-
use glam::{DMat2, Mat2};
33

44
impl From<UnitComplex<f32>> for Mat2 {
55
#[inline]
@@ -17,8 +17,8 @@ impl From<UnitComplex<f64>> for DMat2 {
1717

1818
#[cfg(feature = "convert-glam-unchecked")]
1919
mod unchecked {
20+
use super::super::glam::{DMat2, Mat2};
2021
use crate::{Rotation2, UnitComplex};
21-
use glam::{DMat2, Mat2};
2222

2323
impl From<Mat2> for UnitComplex<f32> {
2424
#[inline]

src/third_party/glam/mod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
mod glam_isometry;
2-
mod glam_matrix;
3-
mod glam_point;
4-
mod glam_quaternion;
5-
mod glam_rotation;
6-
mod glam_similarity;
7-
mod glam_translation;
8-
mod glam_unit_complex;
1+
#[cfg(feature = "glam013")]
2+
mod v013;
3+
#[cfg(feature = "glam014")]
4+
mod v014;
5+
#[cfg(feature = "glam015")]
6+
mod v015;

0 commit comments

Comments
 (0)