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

Multiply BVecN and VecN? Implement Into/From for BVecN to VecN with 1.0:s and 0.0:s #504

Closed
EriKWDev opened this issue Apr 18, 2024 · 1 comment

Comments

@EriKWDev
Copy link

Bitmasks are cool and would be even more useful if they could be multiplied with a vector of same dimension. This could be done either if the BVecN could be converted into a vector of 0.0:s and 1.0:s, or if std::ops::Mul was implemented for the permutations of BVec and all other Vec

let a = vec3a(0.1, -0.5, 10.0);
let mask = a.cmple(Vec3A::splat(0.1);
let b = a * mask; // NOTE: not implemented atm
assert!(b == vec3a(0.1, -0.5, 0.0);

I feel like this could be done for all vecs of same dimensions?

BVec3A * Vec3A, BVec3 * Vec3, BVec3 * IVec3, BVec3 * I16Vec3 and so on..

@bitshifter
Copy link
Owner

For the most part I only support behaviour that is supported in Rust itself. Rust will not let you multiple a f32 or i32 by a bool.

1.0_f32 * true // compile error
1.0_f32 * f32::from(true) // ok

What it does support is a from conversion from bool to float or bool to integer.

1.0_f32 * f32::from(true) // ok

glam also has from impls for creating a Vec3 or IVec3 from a BVec3 or BVec3A, so while what you are proposing won't work the following will

Vec3A::from(BVec3A) * Vec3A, Vec3::from(BVec3) * Vec3, IVec3::from(BVec3) * IVec3, I16Vec3::from(BVec3) * I16Vec3

Possibly .into() will work in these cases as well if the compiler can work out what type conversion you are after.

As for supporting arithmetic operations on vector masks for other vector types, I don't intend to add that for the reasons given above, that is rust itself doesn't support it.

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

No branches or pull requests

2 participants