-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
MudColor: Add Lerp #10275
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
MudColor: Add Lerp #10275
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #10275 +/- ##
==========================================
- Coverage 91.52% 91.52% -0.01%
==========================================
Files 414 414
Lines 12989 12996 +7
Branches 2452 2452
==========================================
+ Hits 11888 11894 +6
Misses 555 555
- Partials 546 547 +1 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
| "--mud-palette-primary-text: rgba(255,255,255,1);", | ||
| "--mud-palette-primary-darken: rgb(62,44,221);", | ||
| "--mud-palette-primary-lighten: rgb(118,106,231);", | ||
| "--mud-palette-primary-hover: rgba(89,74,226,0.058823529411764705);", |
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.
I highly doubt that the human eye can perceive the difference between 0.058823529411764705 and 0.06.
Reasons to avoid fractions:
- They are not human-readable.
- I haven't come across any online tools that work with fractions.
- In real-world color scenarios, no one would create a color with such a fraction.
This is why, in the math operation:
MudBlazor/src/MudBlazor/Utilities/MudColor.cs
Line 567 in b551df2
| public static MudColor operator +(MudColor color1, MudColor color2) |
I also avoid creating
MudColor with high precision alpha fractions. Otherwise, when performing color math, the A value often ends up as a fractional number, which would rarely match with any blending tool from real world which makes it hard to compare it with real world colors.
@danielchalmers @henon opinion?
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.
I am pretty sure these high precision values were copy-pasted from a color swatch tool. I am ok with two digit alpha values.
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.
How about 2 sig figs: 0.059, a difference of 0.3% instead of 2% @ScarletKuro
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 idea was that APercentage
| public double APercentage => Math.Round(A / 255.0, 2); |
Already rounds to two decimal places, so I thought it would make sense to apply this rounding to the string representation as well. I also looked at the W3C CSS Color Module and only saw precision with two decimal places. I'm not an expert in Chroma.js, it seems that the .css() function also returns only two decimal places. That's why imo this default behavior is optimal for human perception, storage, and practice?
Thoughts?
But either way idm three decimal places as well. It was more to rise that current ToString definitely shoudn't have this much decimals.
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.
I think one extra digit is worth it for the accuracy since it's still significantly more readable. Diminishing returns after that.
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.
But your way is definitely common as well
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.
Hmm, I tried using 3-digit precision, and a few issues came up.
- It would be logical to make
APercentageuse 3-digit precision as well, but this breaks more existing tests. - I noticed that even our color picker is using two decimal places of precision.

So, what should we do? Here are the options:
- Leave
MudColorOutputFormats.RGBAwith 2-digit precision, as I originally did. This way, everything will align. - Change
MudColorOutputFormats.RGBAto 3-digit precision, but leaveAPercentagewith 2 digits. TheAPercentageand alpha in RGBA will then be inconsistent. - Change both
MudColorOutputFormats.RGBAandAPercentageto 3-digit precision and update all the tests. This would be the most time-consuming path and would also visually change the color picker, as it would now display alpha with 3-digit precision.
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.
I think two digits are fine. It means we have 100 different levels of opacity. I am pretty sure that no one can judge the difference between 0.53 and 0.525 opacity with the naked eye.
|
I also think methods like |
Ohhhh, the built-in |
|
Not sure -+* operators are useful considering the range 0-255, can do Lerp without them |
They don't hurt, so let's keep them. |
|
Reverted 3 precision for now. because of this post #10275 (comment), waiting for final decision:
Anyways this is ready for review. The palette generator based on tints and shades I will do separately. |
|
|
I'm reverting the precision completely. This will be done in a separate PR. Alpha is just an integer from 0 to 255, so if we divide it by 255 to see the fractions, this is what we get: As we can see, with only two decimal places of precision, some integer values will return the same percentage. For example, both 12 and 13 would round to 0.05. This means that if we wanted to reverse the result, we would never be able to get back to one of these specific integer values. However, with three decimal places of precision, we can differentiate them. |
466402a to
520b3f4
Compare
|
Don't forget (regarding 2% being imperceptible)
https://www.aao.org/eye-health/tips-prevention/how-humans-see-in-color |



Description
Adds Lerp function to MudColor: https://en.wikipedia.org/wiki/Linear_interpolation
Would be useful for: #10263
After looking, I feel like these can be very useful to be inside the MudColor. Lerp is very common thing when working with colors.
How Has This Been Tested?
Unit tests, checked with other lepr online tools that output is tolerable
Type of Changes
Checklist
dev).