glam-rs
glam-rs copied to clipboard
Checked Math for Composite Types
I'd love to be able to do this, for example:
IVec3::ZERO.checked_div(10).ok_or(0)
Thanks.
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.
These were added in #596
Thanks for adding this and the heads up.