yoanlcq / vek

Generic 2D-3D math swiss army knife for game engines, with SIMD support and focus on convenience.
https://docs.rs/vek
Apache License 2.0
282 stars 32 forks source link

Implement more num-traits (e.g. checked arithmetic) #86

Closed Patiga closed 2 years ago

Patiga commented 2 years ago

num-traits has many traits not yet implemented by the Vec types. I personally want the checked math traits, such as CheckedAdd. Without those traits, it's a much bigger hassle to write overflow-avoiding code. For the sake of completeness, other traits, such as the wrapping ones (e.g. WrappingAdd) could also be implemented.

I'd be willing to implementing this myself.

yoanlcq commented 2 years ago

Hi, sorry for the delay.

I see... It looks to me like many such traits in num_traits are implemented on primitive types directly, instead of "any T where T has some trait", but that makes sense implementation-wise...

I think it would be best to go all-out and implement as many of those traits as possible, to make sure there is no need to come back to that later.

I'll try to do that today and get back to you.

Thanks

Patiga commented 2 years ago

Thanks for the reply! I'm really glad I found this crate. I was about to start my own point-crate, because all the other choices were problematic in some way for me. This one is pretty much exactly what I was aiming at. Love it :)

yoanlcq commented 2 years ago

Glad to hear that! :) Out of curiosity, how did you end up finding it? I'm wondering because I didn't promote it, and to my knowledge there is no hugely popular project using it... It might just be that crates.io's search engine did a good job.

Just to let you know, I'm still working on your request, this is progressing slowly because I have very little time at the moment, but I'm not forgetting, and should push a commit soon (in 1 or 2 days I would guess).

Patiga commented 2 years ago

Yeah, I didn't find vek as early as I would've liked. First I used cgmath simply because it was the first thing that did what I wanted. Then my requirements grew, and I wrote my own point type. Since that single type would've grown quite big, I wanted to put it into its own crate, at which point I realized I should go looking for an already existing crate again. All the more popular crates I found didn't quite fit. I found vek when I randomly went through the tags that cgmath uses. vek is the third most downloaded crate under the tag quaternion right now.

Thanks for working on it, no need for rush :) In case it consumes too much time, I can also try to figure it out myself

yoanlcq commented 2 years ago

It's now available in 0.15.9;

(could have been published earlier, but I initially thought there would be a need for a macro similar to vec_impl_binop!, but it turned out there wasn't).

That should do it, I'll close this issue but feel free to re-open if there is some stuff missing or such.

I think there are quite a few more traits that could be implemented, but at least those from num_traits::ops are done!