-
Notifications
You must be signed in to change notification settings - Fork 162
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
Add support for rand
's Uniform
distribution to all Vec types
#580
Add support for rand
's Uniform
distribution to all Vec types
#580
Conversation
…hich will be proxies to UniformInt's impls; plus, remove UniformFloatVec*
…cro, and additionally change a bunch of vec-type constructors to use the From trait, so that it works across all vec types
…le certain traits on `rand::distributions::Uniform`
This was needed with how I was originally building the impls - but I never thought to remove it afterward.
Float vector types seem to fail when running these tests, due to a range overflow, so more work is needed
This looks OK to me so far. |
… of the function We may be able to expand this macro to be used for both int and float purposes, although for now it only covers ints
@bitshifter Thank you. I'm working on cleaning up the code currently, and I still need to make tests for float types; but the main functionality is finished. |
* Reuse `int_rng` and `vec_rng` to reduce the amount of code generated * Clarify the __repeat_code comments * `test_uniform` now generates tests for both ref and non-ref versions * Spread macro parameters as we'll be going over 80 characters
…tests for float types; also implements a new `upper_range_multiplier` parameter on the macro to sidestep the "Range overflow" issue I was getting before with floats
I believe this PR is ready for review and merging. All vec types (except P.S. After this PR is merged, I will probably look at refactoring/rewriting |
Thanks for this! |
Closes #579.
This PR makes the following changes to the
glam
crate:rand
'sUniform
distribution to all Vec typesimpl_rand.rs
file into their relevant macros, easing readability and maintainabilityThis is still a Work-In-Progress
I have yet to do the following:
I suspect that the code quality could also be improved in some places. If you spot any way to improve it, let me know! (or if you're bitshifter, feel free to commit directly to my PR!)
Some notes
The
UniformVec*
structs used to handle uniform distribution are part of a non-public module, and thus cannot be navigated to in the documentation. While I can rectify this upon request, I don't believe it's necessary, since the wayrand
intends for the user to performUniform
distribution is through therand::distributions::Uniform
type, rather than using the backend types directly.I have not added (de)serialization support to the
UniformVec*
structs. However,rand
offers (de)serialization of its distribution structs, so I am unsure if (de)serialization is wanted forUniformVec*
.