diff --git a/Cargo.toml b/Cargo.toml index 8a3fea5c9..a629b5544 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,6 @@ cuda = [ "cust_core", "simba/cuda" ] # Conversion convert-mint = [ "mint" ] convert-bytemuck = [ "bytemuck" ] -convert-glam013 = [ "glam013" ] convert-glam014 = [ "glam014" ] convert-glam015 = [ "glam015" ] convert-glam016 = [ "glam016" ] @@ -88,7 +87,6 @@ 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 } glam016 = { package = "glam", version = "0.16", optional = true } diff --git a/nalgebra-glm/Cargo.toml b/nalgebra-glm/Cargo.toml index f80875814..adf05fa3a 100644 --- a/nalgebra-glm/Cargo.toml +++ b/nalgebra-glm/Cargo.toml @@ -26,7 +26,6 @@ cuda = [ "nalgebra/cuda" ] # Conversion convert-mint = [ "nalgebra/mint" ] convert-bytemuck = [ "nalgebra/bytemuck" ] -convert-glam013 = [ "nalgebra/glam013" ] convert-glam014 = [ "nalgebra/glam014" ] convert-glam015 = [ "nalgebra/glam015" ] convert-glam016 = [ "nalgebra/glam016" ] diff --git a/src/third_party/glam/common/glam_isometry.rs b/src/third_party/glam/common/glam_isometry.rs index 3a8d49618..7b188c39d 100644 --- a/src/third_party/glam/common/glam_isometry.rs +++ b/src/third_party/glam/common/glam_isometry.rs @@ -1,5 +1,5 @@ use super::glam::{DMat3, DMat4, DQuat, DVec2, DVec3, Mat3, Mat4, Quat, Vec2, Vec3}; -use crate::{Isometry2, Isometry3, Matrix3, Matrix4, Translation3, UnitQuaternion, Vector2}; +use crate::{Isometry2, Isometry3, Matrix3, Matrix4, Translation3, UnitQuaternion}; use std::convert::TryFrom; impl From> for Mat3 { @@ -36,18 +36,18 @@ impl From> for (DVec3, DQuat) { } } -impl From> for (Vec3, Quat) { - fn from(iso: Isometry2) -> (Vec3, Quat) { - let tra = Vec3::new(iso.translation.x, iso.translation.y, 0.0); - let rot = Quat::from_axis_angle(Vec3::Z, iso.rotation.angle()); +impl From> for (Vec2, f32) { + fn from(iso: Isometry2) -> (Vec2, f32) { + let tra = Vec2::new(iso.translation.x, iso.translation.y); + let rot = iso.rotation.angle(); (tra, rot) } } -impl From> for (DVec3, DQuat) { - fn from(iso: Isometry2) -> (DVec3, DQuat) { - let tra = DVec3::new(iso.translation.x, iso.translation.y, 0.0); - let rot = DQuat::from_axis_angle(DVec3::Z, iso.rotation.angle()); +impl From> for (DVec2, f64) { + fn from(iso: Isometry2) -> (DVec2, f64) { + let tra = DVec2::new(iso.translation.x, iso.translation.y); + let rot = iso.rotation.angle(); (tra, rot) } } @@ -64,30 +64,6 @@ impl From<(DVec3, DQuat)> for Isometry3 { } } -impl From<(Vec3, Quat)> for Isometry2 { - fn from((tra, rot): (Vec3, Quat)) -> Self { - Isometry2::new([tra.x, tra.y].into(), rot.to_axis_angle().1) - } -} - -impl From<(DVec3, DQuat)> for Isometry2 { - fn from((tra, rot): (DVec3, DQuat)) -> Self { - Isometry2::new([tra.x, tra.y].into(), rot.to_axis_angle().1) - } -} - -impl From<(Vec2, Quat)> for Isometry2 { - fn from((tra, rot): (Vec2, Quat)) -> Self { - Isometry2::new(tra.into(), rot.to_axis_angle().1) - } -} - -impl From<(DVec2, DQuat)> for Isometry2 { - fn from((tra, rot): (DVec2, DQuat)) -> Self { - Isometry2::new(tra.into(), rot.to_axis_angle().1) - } -} - impl From<(Vec2, f32)> for Isometry2 { fn from((tra, rot): (Vec2, f32)) -> Self { Isometry2::new(tra.into(), rot) @@ -112,18 +88,6 @@ impl From for Isometry3 { } } -impl From for Isometry2 { - fn from(rot: Quat) -> Self { - Isometry2::new(Vector2::zeros(), rot.to_axis_angle().1) - } -} - -impl From for Isometry2 { - fn from(rot: DQuat) -> Self { - Isometry2::new(Vector2::zeros(), rot.to_axis_angle().1) - } -} - impl From for Isometry3 { fn from(tra: Vec3) -> Self { Isometry3::from_parts(tra.into(), UnitQuaternion::identity()) @@ -148,18 +112,6 @@ impl From for Isometry2 { } } -impl From for Isometry2 { - fn from(tra: Vec3) -> Self { - Isometry2::new([tra.x, tra.y].into(), 0.0) - } -} - -impl From for Isometry2 { - fn from(tra: DVec3) -> Self { - Isometry2::new([tra.x, tra.y].into(), 0.0) - } -} - impl TryFrom for Isometry2 { type Error = (); diff --git a/src/third_party/glam/common/glam_matrix.rs b/src/third_party/glam/common/glam_matrix.rs index 80f880541..fa9f713f9 100644 --- a/src/third_party/glam/common/glam_matrix.rs +++ b/src/third_party/glam/common/glam_matrix.rs @@ -3,7 +3,11 @@ use super::glam::{ Mat4, UVec2, UVec3, UVec4, Vec2, Vec3, Vec3A, Vec4, }; use crate::storage::RawStorage; -use crate::{Matrix, Matrix2, Matrix3, Matrix4, Vector, Vector2, Vector3, Vector4, U2, U3, U4}; +use crate::{ + Matrix, Matrix2, Matrix3, Matrix4, Unit, UnitVector2, UnitVector3, UnitVector4, Vector, + Vector2, Vector3, Vector4, U2, U3, U4, +}; +use std::convert::TryFrom; macro_rules! impl_vec_conversion( ($N: ty, $Vec2: ty, $Vec3: ty, $Vec4: ty) => { @@ -66,6 +70,63 @@ impl_vec_conversion!(i32, IVec2, IVec3, IVec4); impl_vec_conversion!(u32, UVec2, UVec3, UVec4); impl_vec_conversion!(bool, BVec2, BVec3, BVec4); +const ERR: &'static str = "Normalization failed."; + +macro_rules! impl_unit_vec_conversion( + ($N: ty, $Vec2: ty, $Vec3: ty, $Vec4: ty) => { + impl TryFrom<$Vec2> for UnitVector2<$N> { + type Error = &'static str; + #[inline] + fn try_from(e: $Vec2) -> Result { + Unit::try_new(e.into(), 0.0).ok_or(ERR) + } + } + + impl From> for $Vec2 + { + #[inline] + fn from(e: UnitVector2<$N>) -> $Vec2 { + e.into_inner().into() + } + } + + impl TryFrom<$Vec3> for UnitVector3<$N> { + type Error = &'static str; + #[inline] + fn try_from(e: $Vec3) -> Result { + Unit::try_new(e.into(), 0.0).ok_or(ERR) + } + } + + impl From> for $Vec3 + { + #[inline] + fn from(e: UnitVector3<$N>) -> $Vec3 { + e.into_inner().into() + } + } + + impl TryFrom<$Vec4> for UnitVector4<$N> { + type Error = &'static str; + #[inline] + fn try_from(e: $Vec4) -> Result { + Unit::try_new(e.into(), 0.0).ok_or(ERR) + } + } + + impl From> for $Vec4 + { + #[inline] + fn from(e: UnitVector4<$N>) -> $Vec4 { + e.into_inner().into() + } + } + } +); + +impl_unit_vec_conversion!(f32, Vec2, Vec3, Vec4); +impl_unit_vec_conversion!(f64, DVec2, DVec3, DVec4); + impl From for Vector3 { #[inline] fn from(e: Vec3A) -> Vector3 { @@ -83,6 +144,21 @@ where } } +impl TryFrom for UnitVector3 { + type Error = &'static str; + #[inline] + fn try_from(e: Vec3A) -> Result { + Unit::try_new(e.into(), 0.0).ok_or(ERR) + } +} + +impl From> for Vec3A { + #[inline] + fn from(e: UnitVector3) -> Vec3A { + e.into_inner().into() + } +} + impl From for Matrix2 { #[inline] fn from(e: Mat2) -> Matrix2 { diff --git a/src/third_party/glam/mod.rs b/src/third_party/glam/mod.rs index d24ff7e54..ae2c4514a 100644 --- a/src/third_party/glam/mod.rs +++ b/src/third_party/glam/mod.rs @@ -1,5 +1,3 @@ -#[cfg(feature = "glam013")] -mod v013; #[cfg(feature = "glam014")] mod v014; #[cfg(feature = "glam015")] diff --git a/src/third_party/glam/v013/mod.rs b/src/third_party/glam/v013/mod.rs deleted file mode 100644 index 4787fb216..000000000 --- a/src/third_party/glam/v013/mod.rs +++ /dev/null @@ -1,18 +0,0 @@ -#[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;