Skip to content

fix(hsv): compare CHSV by field instead of by its RGB rendering (#691) - #3807

Merged
zackees merged 1 commit into
masterfrom
fix/691-chsv-equality
Aug 1, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/691-chsv-equality

Conversation

@zackees

@zackees zackees commented Aug 1, 2026 •

Copy link
Copy Markdown
Member

Fixes #691 — open since 2018, and still live.

The bug

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.

The reporter's case:

CHSV(0, 0, 0) == CHSV(128, 0, 0)   // true — both render to black

Writing the test showed it is broader than the report suggests. Every field collapses, 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)

A comparison that silently changes color space answers a question the caller did not ask.

The fix

operator== / operator!= on fl::hsv8, comparing h/s/v directly.

Hidden friends, not members — C++20 synthesizes a reversed candidate for a member operator==, which trips -Wambiguous-reversed-operator at every call site. Same reasoning and same shape as the palette comparisons in colorutils.h (#2724), so this follows the precedent already set in this codebase rather than inventing a new one.

Verification

tests/fl/gfx/hsv.cpp covers 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 lint clean.

Validated locally per the standing instruction to skip GHA for src/ changes.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added direct equality and inequality comparisons for HSV color values.
  • Bug Fixes

    • Comparisons now correctly evaluate hue, saturation, and value fields, including colors that render identically.
  • Tests

    • Added coverage for matching values, individual field differences, and black colors with different hues.

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]>
@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6c94ce8d-fddf-49e8-9e3f-e2c15b3d7c58

📥 Commits

Reviewing files that changed from the base of the PR and between 28d6f37 and b915491.

📒 Files selected for processing (2)
  • src/fl/gfx/hsv.h
  • tests/fl/gfx/hsv.cpp

📝 Walkthrough

Walkthrough

hsv8 now compares its hue, saturation, and value fields directly. Tests cover field differences and HSV values that produce identical RGB output.

Changes

HSV equality operators

Layer / File(s) Summary
Direct HSV comparison and regression coverage
src/fl/gfx/hsv.h, tests/fl/gfx/hsv.cpp
Added operator== and operator!= for direct hsv8 field comparison. Regression tests cover hue, saturation, value, black values, and identical desaturated RGB output.

Estimated code review effort: 2 (Simple) | ~10 minutes

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/691-chsv-equality

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@zackees
zackees merged commit 8e58be5 into master Aug 1, 2026
10 of 12 checks passed
@zackees
zackees deleted the fix/691-chsv-equality branch August 1, 2026 05:47
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Aug 1, 2026
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

CHSV compare (== and !=) converts to CRGB before comparision

1 participant