Repository navigation
fix(hsv): compare CHSV by field instead of by its RGB rendering (#691) - #3807
Merged
Merged
Conversation
CHSV had no operator==, so `a == b` on two CHSV values found no operator on
the type and instead converted BOTH operands to RGB, comparing the rendering
rather than the colors. Anything that rendered alike compared equal.
Reported in 2018 and still live. The reporter's case:
CHSV(0, 0, 0) == CHSV(128, 0, 0) // true -- both render to black
but it is broader than that report suggests. A written test shows every field
collapsing, not just hue at zero saturation:
CHSV(10,20,30) == CHSV(11,20,30) // true (hue differs)
CHSV(10,20,30) == CHSV(10,21,30) // true (saturation differs)
CHSV(10,20,30) == CHSV(10,20,31) // true (value differs -- same RGB)
Adds operator== / operator!= on fl::hsv8 comparing h/s/v directly.
Hidden friends rather than members: C++20 synthesizes a reversed candidate for
a member operator==, which trips -Wambiguous-reversed-operator at every call
site. Same reasoning and shape as the palette comparisons in colorutils.h
(#2724).
tests/fl/gfx/hsv.cpp covers the reporter's exact case, each field in
isolation, and the zero-saturation pair that the RGB path collapsed. It fails
on master and passes here.
Full suite: 275 unit + 83 examples pass, so nothing depended on the old
compare-as-RGB behaviour. Lint clean.
Co-Authored-By: Claude <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesHSV equality operators
Estimated code review effort: 2 (Simple) | ~10 minutes ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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 #691 — open since 2018, and still live.
The bug
CHSVhad nooperator==, soa == bon two CHSV values found no operator on the type and instead converted both operands to RGB, comparing the rendering rather than the colors. Anything that rendered alike compared equal.The reporter's case:
Writing the test showed it is broader than the report suggests. Every field collapses, not just hue at zero saturation:
A comparison that silently changes color space answers a question the caller did not ask.
The fix
operator==/operator!=onfl::hsv8, comparing h/s/v directly.Hidden friends, not members — C++20 synthesizes a reversed candidate for a member
operator==, which trips-Wambiguous-reversed-operatorat every call site. Same reasoning and same shape as the palette comparisons incolorutils.h(#2724), so this follows the precedent already set in this codebase rather than inventing a new one.Verification
tests/fl/gfx/hsv.cppcovers the reporter's exact case, each field in isolation, and the zero-saturation pair the RGB path collapsed. It fails on master and passes here — I wrote and ran it against the unfixed tree first.Full suite: 275 unit + 83 examples pass, so nothing depended on the old compare-as-RGB behaviour. That was the main risk with changing a seven-year-old default.
bash lintclean.Validated locally per the standing instruction to skip GHA for
src/changes.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests