Skip to content

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

Closed
iwek7 wants to merge 1 commit into
bevyengine:mainfrom
iwek7:as_lcha
Closed

iwek7 wants to merge 1 commit into
bevyengine:mainfrom
iwek7:as_lcha

Conversation

@iwek7

@iwek7 iwek7 commented Feb 20, 2023 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

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

Copy link
Copy Markdown
Member

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
Copy Markdown
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
ProfLander pushed a commit to Lander-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.
ProfLander pushed a commit to Lander-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