fix: guard TemperatureCache.complement against a zero temperature range#29
Merged
T-Dynamos merged 2 commits intoJul 13, 2026
Merged
Conversation
A seed whose HCT sits at a tone extreme (#FFFFFF, #000000, ...) collapses the gamut to a single point, so every hue in the 361-entry sweep resolves to the same color and the warmest and coldest entries are identical. complement divided by that zero range and raised ZeroDivisionError, which is reachable from any scheme that needs the complement -- SchemeFidelity, for instance, via get_tertiary_palette. Return the input when the range is zero: every candidate has the same temperature, so none is a better complement than another. This mirrors the zero-range case that relative_temperature already handles, and leaves every non-degenerate seed bit-for-bit unchanged.
CI already runs test_all.py and fails the build on a non-zero exit, so the degenerate seeds fit as an extra construction check alongside the existing ones: without the preceding fix, this raises ZeroDivisionError and the wheel build goes red. Placed ahead of the early exit on Windows so the check runs on every platform.
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 #28
The bug
A seed whose HCT sits at a tone extreme (
#FFFFFF,#000000,#010101) collapses the gamut to a single point, so every hue in the 361-entry sweep resolves to the same color and the warmest and coldest entries are identical.complementdivided by that zero range and raisedZeroDivisionError:#FFFFFFis an ordinary seed for a user to pick, so this is reachable from normal input, viaget_tertiary_palettein any scheme that needs the complement.The fix
Return the input when the range is zero: every candidate has the same temperature, so none is a better complement than another. This mirrors the zero-range case that
relative_temperaturealready handles a few lines below.Verification
Non-degenerate seeds are bit-for-bit unchanged. I compared every color of all 9 dynamic schemes across 5 seeds x light/dark x 4 contrast levels x both spec versions (42,480 values) before and after the change: identical.
The regression check went into
tests/test_all.py, since that is what CI already runs and it fails the build on a non-zero exit — without the fix in the first commit, the second commit makes the wheel build go red. It sits ahead of the early exit on Windows so it runs on every platform. Happy to drop that commit if you would rather keeptest_all.pypurely visual.