Repository navigation
Darken rather than invert a color already darker than the background in AdjustForContrast [patch] - #509
Merged
matt-edmondson merged 3 commits intoNov 4, 2026
Conversation
…kground in AdjustForContrast [patch] The lightness search tried first whichever direction's extreme had more headroom against the background, and kept it whenever it could reach the target. On a background just below luminance 0.179 that meant lightening, even for a dark foreground one step short of the target: #303030 on #737373 for large-text AA became #CECECE instead of #2A2A2A. Both lightness directions are now searched, and when both reach the target the one closer to the original color (by DistanceTo) is returned. The mix fallback keeps its order. Fixes #507 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5Cza8WxR4s8ByZ2GX
…under the complexity limit SonarCloud S3776 flagged AdjustForContrast at cognitive complexity 19 (limit 15) after the both-directions comparison was added inline. The comparison now lives in NearerOf. The new test's two comparisons use Assert.IsLessThan (MSTEST0037). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5Cza8WxR4s8ByZ2GX
SonarCloud S3358 flagged the nested conditional in NearerOf. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5Cza8WxR4s8ByZ2GX
|
matt-edmondson
deleted the
fix/507-adjust-for-contrast-nearest-direction
branch
November 4, 2026 00:54
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.



Fixes #507
What was wrong
AdjustForContrastchose its lightness search direction from the background alone, and kept that direction whenever it could reach the target. On a background just below luminance ~0.179, white has slightly more headroom than black, so lightening always won. That held even for a dark foreground that needed only a nudge darker:Change
Both lightness directions are now searched. When both reach the target, the result closer to the original color by
DistanceTois returned. When only one does, it is used as before. When neither does, the mix fallback keeps its existing order, led by the extreme with more headroom. This is the fix the issue suggested.Tests
AdjustForContrast_DarkensADarkColorOnABackgroundJustBelowTheCrossoverpins the issue's example. The result must meet large-text AA, be darker than#303030, and sit within Oklab distance 0.05 of it.Semantics.Testsuite passes: 1963 passed, 14 skipped, 0 failed. That includes_DarkensOnMidToneBackground,_LightensOnDarkBackground,_KeepsTheHueOfABlueItDarkensand the saturated-color cases.Generated by Claude Code