Node hues share one OKLab lightness, so every name and chip reads alike

The spectrum was an HSV wheel at one saturation and value, which is not
one lightness to the eye: blue names sat at OKLab L 0.55 and yellow at
0.93. A chip's fill is its label at CHIP_LIGHTNESS of that lightness, so
chip contrast followed the label, from APCA Lc 19 on blue to 64 on
yellow.

Each byte now keeps its HSV hue angle and chroma at OKLab L 0.72, with
the chroma fitted where the gamut cannot hold it. JP chose 0.72 on a
ladder of wheels from 0.70 to 0.85. Every name reads equally light and
every chip lands at Lc 34 to 41.

The 256 colours are written out as _NODE_SPECTRUM, because computing
them costs about 14 ms here and _IDENTITY_STYLES needs all of them at
import, which would slow every start on the handhelds. A test holds the
table to _spectrum_hex, and checks one lightness, 256 distinct hues, no
console-slot collision, and that each hue angle is kept.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5.5 committed 2026-10-29 01:05:13 -04:00
1 parent f296413a5e
commit 598e53b488
5 files changed
+147 -18

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
# SPDX-License-Identifier: Apache-2.0
"""Tests for the spectrum of node hues in ``ui/theme.py``: one lightness for each hue."""
from __future__ import annotations
import pytest
from meshterm.ui import oklab, theme
def test_the_written_spectrum_is_the_calculated_one() -> None:
"""The fixed table agrees with :func:`theme._spectrum_hex` for each first key byte.
If this test fails, a constant of the spectrum changed and the table did not. Write the
table again from ``_spectrum_hex``.
"""
assert len(theme._NODE_SPECTRUM) == 256
assert list(theme._NODE_SPECTRUM) == [theme._spectrum_hex(byte) for byte in range(256)]
def test_every_hue_has_the_same_lightness() -> None:
"""Each hue has :data:`theme._NODE_LIGHTNESS` to the eye, within the rounding to 8 bits."""
for colour in theme._NODE_SPECTRUM:
assert oklab.from_hex(colour)[0] == pytest.approx(theme._NODE_LIGHTNESS, abs=0.005)
def test_every_hue_is_its_own_and_none_is_a_console_slot() -> None:
"""The 256 hues are different, and the spectrum never makes a colour of the console.
``is_identity_style`` holds both vocabularies in one set. Thus a spectrum hue that is
also a console slot would make the two vocabularies collide.
"""
assert len(set(theme._NODE_SPECTRUM)) == 256
assert not set(theme._NODE_SPECTRUM) & set(theme._NODE_SLOT_HEXES)
def test_a_node_keeps_the_hue_angle_of_the_hsv_wheel() -> None:
"""Only the lightness and the chroma change. The hue angle of each byte is as before."""
import colorsys
import math
for byte in range(0, 256, 8):
r, g, b = colorsys.hsv_to_rgb(byte / 256, theme._NODE_HUE_SAT, theme._NODE_HUE_VAL)
_, a0, b0 = oklab.from_hex(f"#{round(r * 255):02x}{round(g * 255):02x}{round(b * 255):02x}")
_, a1, b1 = oklab.from_hex(theme._NODE_SPECTRUM[byte])
turn = math.remainder(math.atan2(b1, a1) - math.atan2(b0, a0), math.tau)
assert abs(math.degrees(turn)) < 3, f"{byte:02x}"
+5 -2
View File
@@ -35,7 +35,7 @@ def test_the_wheel_is_not_uniform_to_the_eye() -> None:
"""One hue step is small in green and large in cyan. This is why the module exists."""
green = oklab.distance(_fill("4c"), _fill("5c"))
cyan = oklab.distance(_fill("80"), _fill("90"))
assert green < 0.03 < 0.15 < cyan
assert green < 0.03 < 0.08 < cyan # also on the spectrum of one lightness (2026-10-29)
def test_shaded_moves_lightness_alone_away_from_the_nearer_end() -> None:
@@ -66,10 +66,13 @@ def test_fitted_lowers_chroma_alone_and_keeps_near_hues_apart() -> None:
A colour in the gamut is returned unchanged. The clip in ``to_hex`` made two dark
greens near ``0x50`` almost one colour. After the fit, they are clearly two colours.
The two greens are ``0x4c`` and ``0x5c`` of the HSV wheel that the spectrum used before
2026-10-29. The spectrum of one lightness has less chroma in the greens, so its own
greens leave the gamut less when they are darker.
"""
inside = oklab.from_hex(_fill("80"))
assert oklab.fitted(inside) == inside
darker = [oklab.from_hex(_fill(key)) for key in ("4c", "5c")]
darker = [oklab.from_hex(green) for green in ("#77f255", "#55f26d")]
outside = [(lab[0] * 0.6, lab[1], lab[2]) for lab in darker]
fits = [oklab.fitted(lab) for lab in outside]
clipped = oklab.distance(*(oklab.to_hex(lab) for lab in outside))