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

[Merged by Bors] - Add 'Color::as_lcha' function (#7757) #7766

Closed
wants to merge 1 commit into from

Conversation

iwek7
Copy link
Contributor

@iwek7 iwek7 commented Feb 20, 2023

Objective

Fixes #7757

New function Color::as_lcha was added and Color::as_lch_f32 changed name to Color::as_lcha_f32.


As a side note I did it as in every other Color function, that is I created very simillar code in as_lcha as was in as_lcha_f32. However it is totally possible to avoid this code duplication in LCHA and other color variants by doing something like :

 pub fn as_lcha(self: &Color) -> Color {
    let (lightness, chroma, hue, alpha) = self.as_lcha_f32();
    return Color::Lcha { lightness, chroma, hue, alpha };
}

This is maybe slightly less efficient but it avoids copy-pasting this huge match expression which is error prone. Anyways since it is my first commit here I wanted to be consistent with the rest of code but can refactor all variants in separate PR if somebody thinks it is good idea.

@github-actions
Copy link
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@iwek7 iwek7 force-pushed the as_lcha branch 2 times, most recently from ff325a0 to 22f5327 Compare February 20, 2023 23:23
@alice-i-cecile alice-i-cecile added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Rendering Drawing game state to the screen labels Feb 20, 2023
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC we asked about refactoring this previously, and the idea was rejected by Cart as it's in a very hot loop.

In this unique case, I'd prefer a macro to a function.

@james7132 james7132 modified the milestones: 0.11, 0.10 Mar 5, 2023
@james7132
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Mar 5, 2023
# Objective
Fixes #7757

New function `Color::as_lcha` was added and `Color::as_lch_f32` changed name to `Color::as_lcha_f32`.

----
As a side note I did it as in every other Color function, that is I created very simillar code in `as_lcha` as was in `as_lcha_f32`. However it is totally possible to avoid this code duplication in LCHA and other color variants by doing something like :
```
 pub fn as_lcha(self: &Color) -> Color {
    let (lightness, chroma, hue, alpha) = self.as_lcha_f32();
    return Color::Lcha { lightness, chroma, hue, alpha };
}
```
This is maybe slightly less efficient but it avoids copy-pasting this huge match expression which is error prone. Anyways since it is my first commit here I wanted to be consistent with the rest of code but can refactor all variants in separate PR if somebody thinks it is good idea.
@bors bors bot changed the title Add 'Color::as_lcha' function (#7757) [Merged by Bors] - Add 'Color::as_lcha' function (#7757) Mar 5, 2023
@bors bors bot closed this Mar 5, 2023
Shfty pushed a commit to shfty-rust/bevy that referenced this pull request Mar 19, 2023
# Objective
Fixes bevyengine#7757

New function `Color::as_lcha` was added and `Color::as_lch_f32` changed name to `Color::as_lcha_f32`.

----
As a side note I did it as in every other Color function, that is I created very simillar code in `as_lcha` as was in `as_lcha_f32`. However it is totally possible to avoid this code duplication in LCHA and other color variants by doing something like :
```
 pub fn as_lcha(self: &Color) -> Color {
    let (lightness, chroma, hue, alpha) = self.as_lcha_f32();
    return Color::Lcha { lightness, chroma, hue, alpha };
}
```
This is maybe slightly less efficient but it avoids copy-pasting this huge match expression which is error prone. Anyways since it is my first commit here I wanted to be consistent with the rest of code but can refactor all variants in separate PR if somebody thinks it is good idea.
Shfty pushed a commit to shfty-rust/bevy that referenced this pull request Mar 19, 2023
# Objective
Fixes bevyengine#7757

New function `Color::as_lcha` was added and `Color::as_lch_f32` changed name to `Color::as_lcha_f32`.

----
As a side note I did it as in every other Color function, that is I created very simillar code in `as_lcha` as was in `as_lcha_f32`. However it is totally possible to avoid this code duplication in LCHA and other color variants by doing something like :
```
 pub fn as_lcha(self: &Color) -> Color {
    let (lightness, chroma, hue, alpha) = self.as_lcha_f32();
    return Color::Lcha { lightness, chroma, hue, alpha };
}
```
This is maybe slightly less efficient but it avoids copy-pasting this huge match expression which is error prone. Anyways since it is my first commit here I wanted to be consistent with the rest of code but can refactor all variants in separate PR if somebody thinks it is good idea.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Color::as_lcha
3 participants