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

Implement Color Operations for Color #13285

Merged
merged 1 commit into from May 14, 2024

Conversation

bushrat011899
Copy link
Contributor

Objective

Solution

Delegates to internal type when possible, otherwise uses ChosenColorSpace as an intermediary. This will double convert, but this is considered an acceptable compromise since use of specific colour types in performance critical colour operations is already encouraged.

ChosenColorSpace is Oklcha since it's perceptually uniform while supporting all required operations, and in my opinion is the "best" for this task. Using different spaces for different operations will make documenting this double-conversion behaviour more challenging.

Testing

Changes straightforward enough to not require testing beyond current CI in my opinion.


Changelog

  • Implemented the following traits for Color:
    • Luminance
    • Hue
    • Mix
    • EuclideanDistance
    • ClampColor
  • Added documentation to Color explaining the behaviour of these operations (possible conversion, etc.)

@bushrat011899 bushrat011899 added C-Enhancement A new feature X-Contentious There are nontrivial implications that should be thought through D-Straightforward Simple bug fixes and API improvements, docs, test and examples A-Color Color spaces and color math labels May 9, 2024
@bushrat011899 bushrat011899 marked this pull request as ready for review May 9, 2024 00:45
Copy link
Contributor

@tychedelia tychedelia left a comment

Choose a reason for hiding this comment

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

Personally, I am starting to really like the enum approach. I think this is going to be very expressive for our users who are able to work with Color rather than a specific space.

crates/bevy_color/src/color.rs Show resolved Hide resolved
@alice-i-cecile alice-i-cecile added this to the 0.14 milestone May 9, 2024
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.

I really like the end results here: it provides a great balance between correctness, performance and usability.

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label May 9, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue May 13, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 13, 2024
@alice-i-cecile
Copy link
Member

@bushrat011899 you may need to tweak this to account for the removal of ClampColor.

auto-merge was automatically disabled May 13, 2024 23:57

Head branch was pushed to by a user without write access

Delegates to internal type when possible, otherwise uses `ChosenColorSpace` as an intermediary. This _will_ double convert, but this is considered an acceptable compromise since use of specific colour types in performance critical colour operations is already encouraged.

 `ChosenColorSpace` is `Oklcha` since it's perceptually uniform while supporting all required operations, and in my opinion is the "best" for this task. Using different spaces for different operations will make documenting this double-conversion behaviour more challenging.

Call out explicitly why `Oklcha` is used for operations requiring conversion.
@bushrat011899
Copy link
Contributor Author

@alice-i-cecile should be good to go now!

@alice-i-cecile alice-i-cecile added this pull request to the merge queue May 14, 2024
Merged via the queue into bevyengine:main with commit 6482a03 May 14, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Color Color spaces and color math C-Enhancement A new feature D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Contentious There are nontrivial implications that should be thought through
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement all non-trivial color traits on Color type
4 participants