Skip to content

Commit

Permalink
Support multiple version of the optional glam conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
sebcrozet committed Jun 1, 2021
1 parent ef3257b commit 4af979c
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 28 deletions.
13 changes: 10 additions & 3 deletions Cargo.toml
Expand Up @@ -36,9 +36,13 @@ macros = [ "nalgebra-macros" ]

# Conversion
convert-mint = [ "mint" ]
convert-glam = [ "glam" ]
convert-glam-unchecked = [ "convert-glam" ] # Enable edgy conversions like Mat4 -> Isometry3
convert-bytemuck = [ "bytemuck" ]
convert-glam013 = [ "glam013" ]
convert-glam013-unchecked = [ "convert-glam013" ] # Enable edgy conversions like Mat4 -> Isometry3
convert-glam014 = [ "glam014" ]
convert-glam014-unchecked = [ "convert-glam014" ] # Enable edgy conversions like Mat4 -> Isometry3
convert-glam015 = [ "glam015" ]
convert-glam015-unchecked = [ "convert-glam015" ] # Enable edgy conversions like Mat4 -> Isometry3

# Serialization
## To use serde in a #[no-std] environment, enable the
Expand Down Expand Up @@ -78,13 +82,16 @@ serde = { version = "1.0", default-features = false, features = [ "deri
abomonation = { version = "0.7", optional = true }
rkyv = { version = "~0.6.4", default-features = false, features = ["const_generics"], optional = true }
mint = { version = "0.5", optional = true }
glam = { version = "0.13", optional = true }
quickcheck = { version = "1", optional = true }
pest = { version = "2", optional = true }
pest_derive = { version = "2", optional = true }
bytemuck = { version = "1.5", optional = true }
matrixcompare-core = { version = "0.1", optional = true }
proptest = { version = "1", optional = true, default-features = false, features = ["std"] }
glam013 = { package = "glam", version = "0.13", optional = true }
glam014 = { package = "glam", version = "0.14", optional = true }
glam015 = { package = "glam", version = "0.15", optional = true }


[dev-dependencies]
serde_json = "1.0"
Expand Down
@@ -1,5 +1,5 @@
use super::glam::{DMat3, DMat4, DQuat, DVec3, Mat3, Mat4, Quat, Vec3};
use crate::{Isometry2, Isometry3};
use glam::{DMat3, DMat4, DQuat, DVec3, Mat3, Mat4, Quat, Vec3};

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

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

impl From<(Vec3, Quat)> for Isometry3<f32> {
fn from((tra, rot): (Vec3, Quat)) -> Self {
Expand Down Expand Up @@ -92,6 +92,78 @@ mod unchecked {
}
}

impl From<(Vec2, f32)> for Isometry2<f32> {
fn from((tra, rot): (Vec2, f32)) -> Self {
Isometry2::new([tra.x, tra.y].into(), rot)
}
}

impl From<(DVec2, f64)> for Isometry2<f64> {
fn from((tra, rot): (DVec2, f64)) -> Self {
Isometry2::new([tra.x, tra.y].into(), rot)
}
}

impl From<Quat> for Isometry3<f32> {
fn from(rot: Quat) -> Self {
Isometry3::from_parts(crate::one(), rot.into())
}
}

impl From<DQuat> for Isometry3<f64> {
fn from(rot: DQuat) -> Self {
Isometry3::from_parts(crate::one(), rot.into())
}
}

impl From<Quat> for Isometry2<f32> {
fn from(rot: Quat) -> Self {
Isometry2::new(crate::zero(), rot.to_axis_angle().1)
}
}

impl From<DQuat> for Isometry2<f64> {
fn from(rot: DQuat) -> Self {
Isometry2::new(crate::zero(), rot.to_axis_angle().1)
}
}

impl From<Vec3> for Isometry3<f32> {
fn from(tra: Vec3) -> Self {
Isometry3::from_parts(tra.into(), crate::one())
}
}

impl From<DVec3> for Isometry3<f64> {
fn from(tra: DVec3) -> Self {
Isometry3::from_parts(tra.into(), crate::one())
}
}

impl From<Vec2> for Isometry2<f32> {
fn from(tra: Vec2) -> Self {
Isometry2::new(tra.into(), crate::one())
}
}

impl From<DVec2> for Isometry2<f64> {
fn from(tra: DVec2) -> Self {
Isometry2::new(tra.into(), crate::one())
}
}

impl From<Vec3> for Isometry2<f32> {
fn from(tra: Vec3) -> Self {
Isometry2::new([tra.x, tra.y].into(), crate::one())
}
}

impl From<DVec3> for Isometry2<f64> {
fn from(tra: DVec3) -> Self {
Isometry2::new([tra.x, tra.y].into(), crate::one())
}
}

impl From<Mat3> for Isometry2<f32> {
fn from(mat3: Mat3) -> Isometry2<f32> {
crate::convert_unchecked(Matrix3::from(mat3))
Expand Down
@@ -1,9 +1,9 @@
use crate::storage::Storage;
use crate::{Matrix, Matrix2, Matrix3, Matrix4, Vector, Vector2, Vector3, Vector4, U2, U3, U4};
use glam::{
use super::glam::{
BVec2, BVec3, BVec4, DMat2, DMat3, DMat4, DVec2, DVec3, DVec4, IVec2, IVec3, IVec4, Mat2, Mat3,
Mat4, UVec2, UVec3, UVec4, Vec2, Vec3, Vec3A, Vec4,
};
use crate::storage::Storage;
use crate::{Matrix, Matrix2, Matrix3, Matrix4, Vector, Vector2, Vector3, Vector4, U2, U3, U4};

macro_rules! impl_vec_conversion(
($N: ty, $Vec2: ty, $Vec3: ty, $Vec4: ty) => {
Expand Down
@@ -1,8 +1,8 @@
use crate::{Point2, Point3, Point4};
use glam::{
use super::glam::{
BVec2, BVec3, BVec4, DVec2, DVec3, DVec4, IVec2, IVec3, IVec4, UVec2, UVec3, UVec4, Vec2, Vec3,
Vec3A, Vec4,
};
use crate::{Point2, Point3, Point4};

macro_rules! impl_point_conversion(
($N: ty, $Vec2: ty, $Vec3: ty, $Vec4: ty) => {
Expand Down
@@ -1,5 +1,5 @@
use super::glam::{DQuat, Quat};
use crate::{Quaternion, UnitQuaternion};
use glam::{DQuat, Quat};

impl From<Quat> for Quaternion<f32> {
#[inline]
Expand Down Expand Up @@ -45,8 +45,8 @@ impl From<UnitQuaternion<f64>> for DQuat {

#[cfg(feature = "convert-glam-unchecked")]
mod unchecked {
use super::super::glam::{DQuat, Quat};
use crate::{Quaternion, UnitQuaternion};
use glam::{DQuat, Quat};

impl From<Quat> for UnitQuaternion<f32> {
#[inline]
Expand Down
@@ -1,5 +1,5 @@
use super::glam::{DMat2, DQuat, Mat2, Quat};
use crate::{Rotation2, Rotation3, UnitQuaternion};
use glam::{DMat2, DQuat, Mat2, Quat};

impl From<Rotation2<f32>> for Mat2 {
#[inline]
Expand Down Expand Up @@ -31,8 +31,8 @@ impl From<Rotation3<f64>> for DQuat {

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

impl From<Mat2> for Rotation2<f32> {
#[inline]
Expand Down
@@ -1,5 +1,5 @@
use super::glam::{DMat3, DMat4, Mat3, Mat4};
use crate::{Similarity2, Similarity3};
use glam::{DMat3, DMat4, Mat3, Mat4};

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

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

impl From<Mat3> for Similarity2<f32> {
fn from(mat3: Mat3) -> Similarity2<f32> {
Expand Down
@@ -1,5 +1,5 @@
use super::glam::{DVec2, DVec3, DVec4, Vec2, Vec3, Vec3A, Vec4};
use crate::{Translation2, Translation3, Translation4};
use glam::{DVec2, DVec3, DVec4, Vec2, Vec3, Vec3A, Vec4};

macro_rules! impl_translation_conversion(
($N: ty, $Vec2: ty, $Vec3: ty, $Vec4: ty) => {
Expand Down
@@ -1,5 +1,5 @@
use super::glam::{DMat2, Mat2};
use crate::UnitComplex;
use glam::{DMat2, Mat2};

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

#[cfg(feature = "convert-glam-unchecked")]
mod unchecked {
use super::super::glam::{DMat2, Mat2};
use crate::{Rotation2, UnitComplex};
use glam::{DMat2, Mat2};

impl From<Mat2> for UnitComplex<f32> {
#[inline]
Expand Down
14 changes: 6 additions & 8 deletions src/third_party/glam/mod.rs
@@ -1,8 +1,6 @@
mod glam_isometry;
mod glam_matrix;
mod glam_point;
mod glam_quaternion;
mod glam_rotation;
mod glam_similarity;
mod glam_translation;
mod glam_unit_complex;
#[cfg(feature = "glam013")]
mod v013;
#[cfg(feature = "glam014")]
mod v014;
#[cfg(feature = "glam015")]
mod v015;
18 changes: 18 additions & 0 deletions src/third_party/glam/v013/mod.rs
@@ -0,0 +1,18 @@
#[path = "../common/glam_isometry.rs"]
mod glam_isometry;
#[path = "../common/glam_matrix.rs"]
mod glam_matrix;
#[path = "../common/glam_point.rs"]
mod glam_point;
#[path = "../common/glam_quaternion.rs"]
mod glam_quaternion;
#[path = "../common/glam_rotation.rs"]
mod glam_rotation;
#[path = "../common/glam_similarity.rs"]
mod glam_similarity;
#[path = "../common/glam_translation.rs"]
mod glam_translation;
#[path = "../common/glam_unit_complex.rs"]
mod glam_unit_complex;

pub(self) use glam013 as glam;
18 changes: 18 additions & 0 deletions src/third_party/glam/v014/mod.rs
@@ -0,0 +1,18 @@
#[path = "../common/glam_isometry.rs"]
mod glam_isometry;
#[path = "../common/glam_matrix.rs"]
mod glam_matrix;
#[path = "../common/glam_point.rs"]
mod glam_point;
#[path = "../common/glam_quaternion.rs"]
mod glam_quaternion;
#[path = "../common/glam_rotation.rs"]
mod glam_rotation;
#[path = "../common/glam_similarity.rs"]
mod glam_similarity;
#[path = "../common/glam_translation.rs"]
mod glam_translation;
#[path = "../common/glam_unit_complex.rs"]
mod glam_unit_complex;

pub(self) use glam014 as glam;
18 changes: 18 additions & 0 deletions src/third_party/glam/v015/mod.rs
@@ -0,0 +1,18 @@
#[path = "../common/glam_isometry.rs"]
mod glam_isometry;
#[path = "../common/glam_matrix.rs"]
mod glam_matrix;
#[path = "../common/glam_point.rs"]
mod glam_point;
#[path = "../common/glam_quaternion.rs"]
mod glam_quaternion;
#[path = "../common/glam_rotation.rs"]
mod glam_rotation;
#[path = "../common/glam_similarity.rs"]
mod glam_similarity;
#[path = "../common/glam_translation.rs"]
mod glam_translation;
#[path = "../common/glam_unit_complex.rs"]
mod glam_unit_complex;

pub(self) use glam015 as glam;
1 change: 0 additions & 1 deletion src/third_party/mod.rs
@@ -1,6 +1,5 @@
#[cfg(feature = "alga")]
mod alga;
#[cfg(feature = "glam")]
mod glam;
#[cfg(feature = "mint")]
mod mint;

0 comments on commit 4af979c

Please sign in to comment.