Repository navigation
Change opacity without a round trip through HLC - #16
Merged
Merged
Conversation
change(.opacity, …) converted the color to HLC and back just to set the opacity, which shifted the RGB components by up to about 1e-6 (e.g. green 0 became 1.7e-6). Opacity is the same in every color space, so it now goes through the RGB path. The never reached .opacity branches of the HSB and HLC helpers are removed.
Jeehut
force-pushed
the
wip/opacity-without-hlc
branch
from
October 15, 2026 09:42
7332d3d to
854a590
Compare
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.
Overview
Color.change(.opacity, to:)andchange(.opacity, by:)converted the color to HLC and back just to set the opacity. That round trip shifted the RGB components by up to about 1.7e-6 (pure green got a red component of 1.7e-6). Opacity is the same in every color space, so it now goes through the RGB path. The.opacitycases of the HSB and HLC helpers were never reached and are removed.This is a precision fix: the drift is far below what a display shows, but it makes
change(.opacity, …)keep the RGB values exactly as they were.Split out of #7.
How this was verified
ColorExtTests.changingOpacityKeepsTheRGBComponentschecks three colors with a tolerance of 5e-7 (the float precision of the platform colors is around 1e-7).Red, with
main'sColorExt.swift:Green, this branch: