Fix NaN okhsl/okhsv values when lightness approximates 0 or 1#24691
Merged
alice-i-cecile merged 6 commits intoJun 22, 2026
Conversation
336af6e to
b14b5bb
Compare
a75b37f to
86d1a53
Compare
86d1a53 to
3ef7846
Compare
alice-i-cecile
approved these changes
Jun 21, 2026
kfc35
approved these changes
Jun 22, 2026
kfc35
left a comment
Contributor
There was a problem hiding this comment.
This happens when oklab_l == 0 or 1 while C != 0,
May be a stupid question, but I noticed you also changed the if to check whether C == 0. Would that suffice instead, meaning that you won’t have to early out for oklab_l == 0 or 1? Or is it that just an unrelated clarification
Member
Author
Both are needed. We already checked C isn't 0. I just removed f32::EPSILON as it's arbitrary and doesn't have a good reason. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Fixes the issues found in #24678 (comment) because
LinearRgba::new(1.0, 1.0, 0.9999996, 1.0)converted toOkhsla { hue: 104.03624, saturation: NaN, lightness: 1.0, alpha: 1.0 }which contains NaN.This happens when
oklab_l== 0 or 1 whileC!= 0, e.g. white minus epsilonSolution
Early return okhsl/okhsv when oklab lightness approximates 0 or 1.
Testing
Added more color tests.
With this fix the okhsl lightness slider looks correct:
