-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option to use mint types #16
Comments
Hmmm, that might be a good idea :) I haven't used |
I’ve used it a little bit. It basically provides a common interface that any math library can implement. From the usage I have seen and used, client usage would look exactly the same as usual: let v = glam::Vec3::new();
do_thing(v); Or: let v = cgmath::Vec3::new();
do_thing(v); For example. On the library side, something like this: fn do_thing(v: Into<mint::Vec3>) {
let v: glam::Vec3 = v.into().into();
…
} IIRC, most of the popular maths libraries have a feature that can be enabled to add implementations to and from mint types. |
Thanks for the TL;DR! 🥇 That's not bad for a glue layer! Seems like quite a few crates use Not sure when I'll have the time to look into it, so I'll flag this issue as "help wanted" in case anyone gets inspired :D |
Looking at it a bit more, I think this is a more representative example of what it would look like. The main thing to note from a usage point is needing to specify the return type: use glam::Vec3;
use mint::Vector3;
fn main() {
let a = Vec3::new(1.0, 2.0, 3.0);
let b = Vec3::new(10.0, 20.0, 30.0);
let c: Vec3 = add(a, b);
assert_eq!(c, Vec3::new(11.0, 22.0, 33.0));
}
fn add<V, U>(a: V, b: V) -> U
where
V: Into<Vector3<f32>>,
U: From<Vector3<f32>>,
{
let a: Vec3 = a.into().into();
let b: Vec3 = b.into().into();
U::from((a + b).into())
} |
From an implementation perspective, do you prefer the previous example or the following style? fn main() {
let a = Vec3::new(1.0, 2.0, 3.0);
let b = Vec3::new(10.0, 20.0, 30.0);
let c: Vec3 = add(a, b);
assert_eq!(c, Vec3::new(11.0, 22.0, 33.0));
}
fn add<V: Into<Vector3<f32>>, U: From<Vector3<f32>>>(a: V, b: V) -> U {
let a: Vec3 = a.into().into();
let b: Vec3 = b.into().into();
U::from((a + b).into())
} |
The one with separate Thanks for looking into this! |
I'm trying to migrate to dolly 0.6 and don't understand how these mint types are meant to be used:
doesn't work because Like so:
Thanks. |
How would you feel about changing the public API to use mint types?
It could help avoid glam version issues and make it easier to use with other maths crates too.
The text was updated successfully, but these errors were encountered: