-
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
Convert all colors to be generic over floats, f32 and f64 #18
Conversation
|
|
||
display_colors("examples/readme_color_spaces.png", &[Rgb::srgb(0.8, 0.2, 0.1).to_srgb(), new_color.to_srgb()]); | ||
display_colors("examples/readme_color_spaces.png", | ||
&[Rgb::srgb(0.8, 0.2, 0.1).to_srgb(), new_color.to_srgb()]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and following calls to the same function are still reformatted.
One of the failing tests can be fixed with |
The reason I didn't change those was because they are documentation tests. Didn't want to have anything too complicated in the docs. |
Cleaned up all the formatting issues. Also made into for hues separate for f32 and f64 |
Good point. Those examples could definitely be improved, but let's try to work around it for now. It looks like the |
clamp(to_srgb(self.red), T::zero(), T::one()), | ||
clamp(to_srgb(self.green), T::zero(), T::one()), | ||
clamp(to_srgb(self.blue), T::zero(), T::one()), | ||
clamp(self.alpha, T::zero(), T::one())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The closing parenthesis is still on the wrong line...
If I remove the GetHue test for green, blue is failing with
|
to_gamma test passes with the change to f32 |
Yet another precision error...
Great! 😄 |
Blue is not only a precision error, its a negative sign ie -180-180 range. Its comparing -120 to 240. Are we showing hue output in -180-180 or [0-360] for now |
Debug prints are shown as the are stored, since that may help debugging. The sign isn't really the problem here, though, since |
I got this example to pass
|
That defeats parts of the purpose and we could just as well use |
Good catch. It passes.
|
Cool! What about doing something like this instead: |
I filed issue #21 as an effect of this madness. |
Readme change is done. All the formatting changes listed above are done. Also changed the example to use f32 impl. |
I saw that |
normalize_angle(self.0) * T::from(PI).unwrap() / T::from(180.0).unwrap() | ||
} | ||
|
||
///Returns the hue value as a f32 or f64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This description should be more general.
I think this is more or less done. It was just that description I commented on now, but the rest is good enough. I'm going to pretend that I didn't see those last few formatting changes, because I'm tired of hunting them down and the show must go on. They are quite small, anyway. Now, on to the final act. I think it may be a good idea to squash everything into one commit again. I would also appreciate it if you could summarize the changes in the top comment (somewhat like in the first PR) and add a note that this is a breaking change. Then I think it's ready to be merged. |
Change all colors (Color, Rgb, Hsl, Hsv, Lab, Xyz) and traits (Mix and Saturation etc) to be generic over floats. This is a breaking change. Since Rust defaults to f64, most of the color types will default to f64. For example Rgb::linear_rgb(1.0, 0.0, 0.0) will be inferred as Rgb<f64>. To use f32, constants must be explicitly set like Rgb::linear_rgb(1.0_f32, 0.0, 0.0) or the type explicitly annotated. T::from( constant ).unwrap() etc was used in a number of places to convert constants to num::Float trait ( via the num::Numcast trait). For Hues, the Into<T> trait was not generic over floats due to unwrap() and possibility of runtime panic and was separately implemented for f32 and f64 for Hue<32> and Hue<64>. Also the Partial Eq trait could not be implemented for Hues as float and was removed. The RgbPixel could not be made generic for [T;3] and (T,T,T) and was separately implemented for f32, f64 and u8. Using associated typed for Mix and Saturation was not ergonomic and the trait was made generic over float. s
I don't know if you understood it correctly. That summary you wrote in the commit message should go into the PR description (a.k.a. your first comment in this thread). See CONTRIBUTING.md. |
Yeah, forgot that this was not a new PR. Thanks for being so patient. |
Don't worry about it. You forgot to mention that it closes #13, but I can squeeze it in there, myself. |
I have looked through it again to see if I missed anything important and it looks alright. Thank you for all of this and for putting up with me being somewhat pedantic. @homu r+ |
📌 Commit 5ae93ac has been approved by |
⚡ Test exempted - status |
Convert all colors to be generic over floats, f32 and f64 **Convert all colors to be generic over floats** Change all colors (Color, Rgb, Hsl, Hsv, Lab, Xyz) and traits (Mix and Saturation etc) to be generic over floats and closes #13. **_This is a breaking change. Type f32 or f64 must be explicitly annotated._** ``` // OLD let new_color: Rgb = lch_color.shift_hue(180.0.into()).into(); // NEW let new_color: Rgb<f32> = lch_color.shift_hue(180.0.into()).into(); ``` Since Rust defaults to f64, most of the color types will default to f64. For example Rgb::linear_rgb(1.0, 0.0, 0.0) will be inferred as Rgb\<f64\>. To use f32, constants must be explicitly set like rgb::linear_rgb(1.0_f32, 0.0, 0.0) or the type explicitly annotated. T::from( constant ).unwrap() etc is used in a number of places to convert constants to num::Float trait ( via the num::Numcast trait). For Hues, the Into<T> trait is not generic over floats due to unwrap() and possibility of runtime panic and is separately implemented for f32 and f64 for Hue\<32\> and Hue\<64\>. Also the Partial Eq trait could not be implemented for Hues as float and was removed. The RgbPixel could not be made generic for [T;3] and (T,T,T) and is separately implemented for f32, f64 and u8. Using associated typed for Mix and Saturation is not ergonomic and the trait was made generic over float.
Separate sRGB and gamma encoded RGB from the Rgb type This closes #7 by adding separate types for sRGB and gamma encoded RGB. `Rgb` becomes a purely linear variant of sRGB and the types for encoded sRGB and gamma RGB can be found in a newly added `pixel` module. The `RgbPixel` trait has also been moved to the `pixel` module. The `linear_*` prefix has also been dropped from the `Rgb` constructors and some bugs from #18 were fixed as a bonus. This is a breaking change, since it moves, removes and renames a lot of functions, and the `RgbPixel` trait is no longer available in the crate root.
Convert all colors to be generic over floats
Change all colors (Color, Rgb, Hsl, Hsv, Lab, Xyz) and traits (Mix and Saturation etc) to be generic over floats and closes #13.
This is a breaking change. Type f32 or f64 must be explicitly annotated.
Since Rust defaults to f64, most of the color types will default to f64. For example Rgb::linear_rgb(1.0, 0.0, 0.0) will be inferred as Rgb. To use f32, constants must be explicitly set like rgb::linear_rgb(1.0_f32, 0.0, 0.0) or the type explicitly annotated.
T::from( constant ).unwrap() etc is used in a number of places to convert constants to num::Float trait ( via the num::Numcast trait).
For Hues, the Into trait is not generic over floats due to unwrap() and possibility of runtime panic and is separately implemented for f32 and f64 for Hue<32> and Hue<64>. Also the Partial Eq trait could not be implemented for Hues as float and was removed.
The RgbPixel could not be made generic for [T;3] and (T,T,T) and is separately implemented for f32, f64 and u8.
Using associated typed for Mix and Saturation is not ergonomic and the trait was made generic over float.