Created
September 24, 2021 17:41
-
-
Save cwfitzgerald/c4e6b53e1daec4e4d75679cec33b9bc9 to your computer and use it in GitHub Desktop.
Mint Workaround
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use nalgebra as na; | |
macro_rules! conversions { | |
($trait1:ident, $conv1:ident, $trait2:ident, $conv2:ident, $(($src:ty, $mint:ty, $dst:ty)),* $(,)?) => { | |
$( | |
impl $trait1 for $src { | |
type Target = $dst; | |
fn $conv1(self) -> Self::Target { | |
let m: $mint = self.into(); | |
m.into() | |
} | |
} | |
impl $trait2 for $dst { | |
type Target = $src; | |
fn $conv2(self) -> Self::Target { | |
let m: $mint = self.into(); | |
m.into() | |
} | |
} | |
)* | |
}; | |
} | |
pub trait GlamToNa { | |
type Target; | |
fn into_na(self) -> Self::Target; | |
} | |
impl<T> GlamToNa for &T | |
where | |
T: GlamToNa + Copy, | |
{ | |
type Target = T::Target; | |
fn into_na(self) -> Self::Target { | |
<T as GlamToNa>::into_na(*self) | |
} | |
} | |
pub trait NaToGlam: Sized { | |
type Target; | |
fn into_glam(self) -> Self::Target; | |
} | |
impl<T> NaToGlam for &T | |
where | |
T: NaToGlam + Copy, | |
{ | |
type Target = T::Target; | |
fn into_glam(self) -> Self::Target { | |
<T as NaToGlam>::into_glam(*self) | |
} | |
} | |
conversions!( | |
GlamToNa, | |
into_na, | |
NaToGlam, | |
into_glam, | |
(glam::Vec2, mint::Vector2<f32>, na::Vector2<f32>), | |
(glam::Vec3, mint::Vector3<f32>, na::Vector3<f32>), | |
(glam::Vec4, mint::Vector4<f32>, na::Vector4<f32>), | |
(glam::DVec2, mint::Vector2<f64>, na::Vector2<f64>), | |
(glam::DVec3, mint::Vector3<f64>, na::Vector3<f64>), | |
(glam::DVec4, mint::Vector4<f64>, na::Vector4<f64>), | |
(glam::IVec2, mint::Vector2<i32>, na::Vector2<i32>), | |
(glam::IVec3, mint::Vector3<i32>, na::Vector3<i32>), | |
(glam::IVec4, mint::Vector4<i32>, na::Vector4<i32>), | |
(glam::UVec2, mint::Vector2<u32>, na::Vector2<u32>), | |
(glam::UVec3, mint::Vector3<u32>, na::Vector3<u32>), | |
(glam::UVec4, mint::Vector4<u32>, na::Vector4<u32>), | |
(glam::Mat2, mint::ColumnMatrix2<f32>, na::Matrix2<f32>), | |
(glam::Mat3, mint::ColumnMatrix3<f32>, na::Matrix3<f32>), | |
(glam::Mat4, mint::ColumnMatrix4<f32>, na::Matrix4<f32>), | |
(glam::DMat2, mint::ColumnMatrix2<f64>, na::Matrix2<f64>), | |
(glam::DMat3, mint::ColumnMatrix3<f64>, na::Matrix3<f64>), | |
(glam::DMat4, mint::ColumnMatrix4<f64>, na::Matrix4<f64>), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment