From 2dae1ca44f4492c2bee7f476f4e6cb90f73341d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crozet=20S=C3=A9bastien?= Date: Sat, 6 Mar 2021 12:39:43 +0100 Subject: [PATCH] Add conversion of Similarity from/to glam types. --- src/third_party/glam/glam_similarity.rs | 54 +++++++++++++++++++++++++ src/third_party/glam/mod.rs | 1 + 2 files changed, 55 insertions(+) create mode 100644 src/third_party/glam/glam_similarity.rs diff --git a/src/third_party/glam/glam_similarity.rs b/src/third_party/glam/glam_similarity.rs new file mode 100644 index 00000000..92107074 --- /dev/null +++ b/src/third_party/glam/glam_similarity.rs @@ -0,0 +1,54 @@ +use crate::{Similarity2, Similarity3}; +use glam::{DMat3, DMat4, Mat3, Mat4}; + +impl From> for Mat3 { + fn from(iso: Similarity2) -> Mat3 { + iso.to_homogeneous().into() + } +} +impl From> for Mat4 { + fn from(iso: Similarity3) -> Mat4 { + iso.to_homogeneous().into() + } +} + +impl From> for DMat3 { + fn from(iso: Similarity2) -> DMat3 { + iso.to_homogeneous().into() + } +} +impl From> for DMat4 { + fn from(iso: Similarity3) -> DMat4 { + iso.to_homogeneous().into() + } +} + +#[cfg(feature = "convert-glam-unchecked")] +mod unchecked { + use crate::{Matrix3, Matrix4, Similarity2, Similarity3}; + use glam::{DMat3, DMat4, Mat3, Mat4}; + + impl From for Similarity2 { + fn from(mat3: Mat3) -> Similarity2 { + crate::convert_unchecked(Matrix3::from(mat3)) + } + } + + impl From for Similarity3 { + fn from(mat4: Mat4) -> Similarity3 { + crate::convert_unchecked(Matrix4::from(mat4)) + } + } + + impl From for Similarity2 { + fn from(mat3: DMat3) -> Similarity2 { + crate::convert_unchecked(Matrix3::from(mat3)) + } + } + + impl From for Similarity3 { + fn from(mat4: DMat4) -> Similarity3 { + crate::convert_unchecked(Matrix4::from(mat4)) + } + } +} diff --git a/src/third_party/glam/mod.rs b/src/third_party/glam/mod.rs index 55dc82c1..d4f8b643 100644 --- a/src/third_party/glam/mod.rs +++ b/src/third_party/glam/mod.rs @@ -3,4 +3,5 @@ mod glam_matrix; mod glam_point; mod glam_quaternion; mod glam_rotation; +mod glam_similarity; mod glam_unit_complex;