Skip to content
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

Make color constructors const and remove or replace all with_wp #239

Merged
merged 1 commit into from
Jul 15, 2021

Conversation

Ogeon
Copy link
Owner

@Ogeon Ogeon commented Jul 15, 2021

I went through the color constructors and made them const fn (or made a const fn version of them). The named colors are using them now!

I did also change the naming so that new is always producing a fully generic type and names like new_srgb can be used for specialized constructors. It's easier to discover via searching or auto complete if the name contains "new". I removed with_wp while doing this, except in Hsv, Hsl and Hwb where I figured it would be good to still have an sRGB specialization. They are more likely to be "entry points" than most other types.

Closed Issues

Breaking Change

The renamed and removed constructors will cause some breakage. Type inference will also be affected and may require additional type hints.

@Ogeon
Copy link
Owner Author

Ogeon commented Jul 15, 2021

I couldn't convert any function that moves out of any kind of value in any way, like from_components((red, green, blue): (T, T, T)) -> Self, That's not yet stabilized.

@github-actions
Copy link

Benchmark for d4a1777

Click to view benchmark
Test PR Benchmark Master Benchmark %
Cie family/lab to lch 3.0±0.00µs 3.0±0.00µs 0.00%
Cie family/lab to xyz 816.4±0.48ns 817.3±0.63ns -0.11%
Cie family/lch to lab 2.1±0.00µs 2.1±0.00µs 0.00%
Cie family/linsrgb to xyz 3.2±0.00µs 3.2±0.03µs 0.00%
Cie family/xyz to lab 9.1±0.01µs 9.1±0.01µs 0.00%
Cie family/xyz to yxy 618.1±0.48ns 617.5±0.33ns +0.10%
Cie family/yxy to xyz 571.8±0.37ns 571.7±0.37ns +0.02%
Matrix functions/matrix_inverse 10.8±0.01ns 11.4±0.01ns -5.26%
Matrix functions/multiply_3x3 9.5±0.00ns 9.1±0.01ns +4.40%
Matrix functions/multiply_rgb_to_xyz 4.1±0.00ns 4.1±0.00ns 0.00%
Matrix functions/multiply_xyz 4.1±0.00ns 4.1±0.00ns 0.00%
Matrix functions/multiply_xyz_to_rgb 4.1±0.01ns 4.1±0.00ns 0.00%
Matrix functions/rgb_to_xyz_matrix 21.2±0.05ns 21.5±0.01ns -1.40%
Rgb family/hsl to hsv 621.8±0.38ns 621.9±0.35ns -0.02%
Rgb family/hsl to linear hsl 8.2±0.00µs 8.2±0.00µs 0.00%
Rgb family/hsl to rgb 2.1±0.00µs 2.1±0.00µs 0.00%
Rgb family/hsv to hsl 987.0±5.88ns 975.6±4.90ns +1.17%
Rgb family/hsv to hwb 237.7±0.31ns 229.9±0.23ns +3.39%
Rgb family/hsv to linear hsv 7.6±0.00µs 7.6±0.01µs 0.00%
Rgb family/hsv to rgb 2.1±0.00µs 2.1±0.00µs 0.00%
Rgb family/hwb to hsv 477.8±4.12ns 479.2±0.23ns -0.29%
Rgb family/hwb to linear hwb 9.3±0.10µs 9.4±0.01µs -1.06%
Rgb family/linear hsl to hsl 8.7±0.01µs 8.5±0.01µs +2.35%
Rgb family/linear hsv to hsv 8.2±0.00µs 8.2±0.00µs 0.00%
Rgb family/linear hwb to hwb 10.0±0.01µs 10.0±0.01µs 0.00%
Rgb family/linsrgb to rgb 4.0±0.00µs 4.0±0.01µs 0.00%
Rgb family/linsrgb_f32 to rgb_u8 5.4±0.01µs 5.4±0.01µs 0.00%
Rgb family/rgb to hsl 741.1±0.34ns 741.3±0.52ns -0.03%
Rgb family/rgb to hsv 565.4±0.49ns 545.4±0.36ns +3.67%
Rgb family/rgb to linsrgb 4.3±0.02µs 4.3±0.00µs 0.00%
Rgb family/rgb_u8 to linsrgb_f32 4.6±0.00µs 4.6±0.00µs 0.00%
Rgb family/xyz to linsrgb 7.0±0.00µs 7.0±0.01µs 0.00%

@Ogeon
Copy link
Owner Author

Ogeon commented Jul 15, 2021

bors r+

@bors
Copy link
Contributor

bors bot commented Jul 15, 2021

Build succeeded:

@bors bors bot merged commit 4763ced into master Jul 15, 2021
@bors bors bot deleted the const_fn branch July 15, 2021 20:54
@mockersf
Copy link

mockersf commented Mar 19, 2023

@Ogeon would it be possible to have a released version with this PR? And others that weren't released yet

@Ogeon
Copy link
Owner Author

Ogeon commented Mar 19, 2023

I will do it sooner than later. I will start looking through it today to make sure I didn't forget anything important. My day job has just been quite draining recently so I haven't had much energy (and time) for it during the past few weeks.

@Ogeon Ogeon changed the title Make color constructors const and remove or replace all with_wp Make color constructors const and remove or replace all with_wp Mar 19, 2023
@mockersf
Copy link

Thank you for your reply.

Do take care!

@Ogeon
Copy link
Owner Author

Ogeon commented Mar 20, 2023

I have started writing up a quick blog post to summarize the changes, so it should be done sometime this week if nothing comes in the way. 🙂

Do take care!

Thanks! I know it hasn't been fun for those who are waiting for the next release but this is how I keep it at a good level. No need to worry! I will try to separate breaking and non-breaking changes in the future so I can make smaller releases. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mark new functions as const
2 participants