-
Notifications
You must be signed in to change notification settings - Fork 61
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
use macros for float conversions #33
Comments
The other two will just shave off a few characters, so I think we can live with |
What is the advantage of using a function instead of a macro? |
It's more generic than an assumed type |
This works
|
Cool! |
I'll make this change once we merge the yxy color. Otherwise there will be too many conflicts. |
Sounds good. One thing at the time 😄 |
Using a function requires type annotations in some cases while the macro does not:
vs
Do you have a preference for either? |
That's not too bad, IMO. It's significantly less noise, compared to the unwraps. I wonder if this would work: let c255: T = flt(255.0);
Rgb {
red: flt(red) / c255,
green: flt(green) / c255,
blue: flt(blue) / c255,
} ...or if it still needs to know the left hand side fist. In any case, I'm still biased towards a function, since it's possible in a reasonable way. I prefer to only use macros where nothing else helps, such as repetitive parts and/or in cases like |
No, the first parameter of a formula (or start of open brace) needs to be of known type T. I have both methods working, if you want to check the difference |
I suspected as much, but I wanted to believe.
Nice! It looks like the function works fine in the critical parts, where the rest of the code is complicated enough as it is. My opinion is that it's completely acceptable. It may not be pretty, but it's at least isolated to the easy parts, as far as I can see, and the intent is clearer than with a macro. |
use flt() function Use function flt() to convert constants to trait Float type. Changed all T::from().unwrap() to use this flt() function defined in lib.rs. Makes the code easier to read, especially the formula's. closes #33
Define three macros
The the equation become easier to read
becomes
The text was updated successfully, but these errors were encountered: