Skip to content
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

Open
junglie85 opened this issue May 25, 2023 · 7 comments
Open

Option to use mint types #16

junglie85 opened this issue May 25, 2023 · 7 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@junglie85
Copy link
Contributor

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.

@h3r2tic
Copy link
Owner

h3r2tic commented May 26, 2023

Hmmm, that might be a good idea :) I haven't used mint myself, is it good?

@junglie85
Copy link
Contributor Author

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.

@h3r2tic
Copy link
Owner

h3r2tic commented May 28, 2023

Thanks for the TL;DR! 🥇 That's not bad for a glue layer! Seems like quite a few crates use mint too, so yeah, let's do it for dolly too!

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

@h3r2tic h3r2tic added enhancement New feature or request help wanted Extra attention is needed labels May 28, 2023
@junglie85
Copy link
Contributor Author

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())
}

@junglie85
Copy link
Contributor Author

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())
}

@h3r2tic
Copy link
Owner

h3r2tic commented Jun 2, 2023

The one with separate where looks a bit more readable to me :) Might be good to also fully qualify mint::Vector3 there, just to make it extra clear to anyone reading the code.

Thanks for looking into this!

@frnsys
Copy link

frnsys commented Jul 28, 2024

I'm trying to migrate to dolly 0.6 and don't understand how these mint types are meant to be used:

        let v = glam::Vec3::Z * -ev.y * ZOOM_DAMP;
        state.rig.driver_mut::<Arm>().offset += v.into();

doesn't work because mint::vector::Vector3<f32> doesn't implement AddAssign (the mint types don't implement any operations at all). So do I need to first convert the offset to a glam type, add, then re-convert back to the mint type?

Like so:

        let mut offset: glam::Vec3 =
            state.rig.driver_mut::<Arm>().offset.into();
        offset += glam::Vec3::Z * -ev.y * ZOOM_DAMP;
        state.rig.driver_mut::<Arm>().offset = offset.into();

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants