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

Component-wise multiplication for Vector2 #475

Closed
alexkirsz opened this issue Feb 22, 2021 · 2 comments · Fixed by #476
Closed

Component-wise multiplication for Vector2 #475

alexkirsz opened this issue Feb 22, 2021 · 2 comments · Fixed by #476

Comments

@alexkirsz
Copy link

alexkirsz commented Feb 22, 2021

Hey,

I don't see an obvious way to do component-wise multiplication and division for Vector2-like types. Is this a deliberate API decision or just a use case that hasn't showed up?

Example usage:

let v1 = Vector2::new(1, 2);
let v2 = Vector2::new(3, 4);
let v3 = v1.component_mul(&v2); // x: 3, y: 8

See also: https://docs.rs/nalgebra/0.24.1/nalgebra/base/struct.Matrix.html#method.component_mul

Cheers,
Alex

@nical
Copy link
Contributor

nical commented Feb 23, 2021

Hi,

Sounds good to me. I suspect that the need hasn't shown up enough for someone to add the API but it makes sense.

I'm wondering if in addition to a properly explicit function like component_mul, adding a Mul operator would make sense. I'm used to having it in glsl.

@alexkirsz
Copy link
Author

@nical Thanks for the quick implementation!

I think it would make sense to also have component-wise division, as well as component-wise ceiling division for integer types.

See:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants