glam-rs icon indicating copy to clipboard operation
glam-rs copied to clipboard

Checked Math for Composite Types

Open nixpulvis opened this issue 1 year ago • 1 comments

I'd love to be able to do this, for example:

IVec3::ZERO.checked_div(10).ok_or(0)

Thanks.

nixpulvis avatar Aug 29 '24 20:08 nixpulvis

I assume the return type of

IVec3::ZERO.checked_div(10).ok_or(0)

should be an IVec3, so it might look more like

IVec3::ZERO.checked_div(10).ok_or(IVec3::ZERO)

but that's dividing a vector by a scalar so most likely I'd also need

IVec3::ZERO.checked_div(IVec3::splat(10)).ok_or(IVec3::ZERO)

It would be a lot of new methods

A try_map<F>(f: F) -> Option<Self> might work for your example here, but while that might work for dividing by a scalar but it wouldn't work for dividing by a vector.

bitshifter avatar Oct 30 '24 09:10 bitshifter

These were added in #596

bitshifter avatar Jun 12 '25 09:06 bitshifter

Thanks for adding this and the heads up.

nixpulvis avatar Jun 29 '25 14:06 nixpulvis