mirror of
https://github.com/donlucasx/xscapes.git
synced 2026-10-20 08:43:32 +02:00
Index256Keeping searches cube corners for one that preserves the source's
channel ordering. Grey has no ordering, so a grey answer fails that check by
definition -- and the search then goes looking for a cube colour that passes,
which in the dark means the pure #0000xx column. A midnight sky came out in
saturated navy over a teal sea, which is precisely the "electric royal blue
that swallows the moon" Shore.BlueSky records as rendered and rejected in
August. It went out in 8ebe101 and was pushed.
Nothing caught it because every test written this session was about colour
being PRESENT. None was about it being absent on purpose. Washing out and
turning the wrong colour are different failures and only one of them is a bug,
so the function now returns a grey answer untouched and is only allowed to fix
orderings between cube colours.
TestTheNightStaysMonochromeOn256 holds it, proven red without the guard
(chroma 135 at midnight) and green with it (chroma 0 at every night hour). It
finds the beach by colour rather than by SandTop, which sits a row above the
dry sand and let a legitimately brown row into the measurement.
The night also reads BETTER than before any of this: the greyscale ramp has
24 steps of 10 luma against the cube's six per channel, so leaving it alone
took 01:00 from three distinct sky tones to six.
Also adds the glyph audit, which is what turned this up. It renders each hour
twice, truecolor against 256, and compares every glyph cell. Glyphs are in
much better shape than the backgrounds were: 0.6% wash out, all of it at night,
and 3.9% take a wrong hue, mostly at twilight. Its first version counted a
glyph that went grey as a hue flip too and read four times high.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013LYGyDmCPYwdBaJYDxnZhy
124 lines
3.9 KiB
Go
124 lines
3.9 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"sort"
|
|
"testing"
|
|
|
|
"github.com/donlucasx/xscapes/internal/canvas"
|
|
"github.com/donlucasx/xscapes/internal/companion"
|
|
"github.com/donlucasx/xscapes/internal/reduce"
|
|
"github.com/donlucasx/xscapes/internal/scape"
|
|
"github.com/donlucasx/xscapes/internal/term"
|
|
)
|
|
|
|
// The 256 audit has only ever been run on backgrounds. This runs it on every
|
|
// GLYPH the scene draws, at every hour, by rendering the frame twice -- once as
|
|
// truecolor, which gives the colour the scene asked for, and once as 256, which
|
|
// gives the colour Terminal.app paints -- and comparing them cell by cell.
|
|
//
|
|
// Two failures are looked for, and they are different things:
|
|
//
|
|
// - COLOUR LOST: the source had real chroma and the terminal painted a grey.
|
|
// - HUE FLIPPED: the source stated a channel ordering clearly and the painted
|
|
// colour reverses it, which is how a blue becomes a violet.
|
|
func TestProbeGlyphColoursOn256(t *testing.T) {
|
|
const w, h = 90, 30
|
|
work := []string{
|
|
"read internal/auth/handler.go 142 lines",
|
|
"edit internal/auth/handler.go +18 -2",
|
|
"shell go test ./... 4.1s",
|
|
"grep rate.Limiter 3 files",
|
|
}
|
|
tail := make([]reduce.Line, 0, len(work))
|
|
for i, s := range work {
|
|
tail = append(tail, reduce.Line{Text: s, Age: 1 - float64(i+1)/float64(len(work))})
|
|
}
|
|
chromaOf := func(c term.RGB) int {
|
|
mx, mn := int(c.R), int(c.R)
|
|
for _, v := range []int{int(c.G), int(c.B)} {
|
|
if v > mx {
|
|
mx = v
|
|
}
|
|
if v < mn {
|
|
mn = v
|
|
}
|
|
}
|
|
return mx - mn
|
|
}
|
|
flipped := func(src, q term.RGB) bool {
|
|
pair := func(a, b, qa, qb uint8) bool {
|
|
switch d := int(a) - int(b); {
|
|
case d >= 25:
|
|
return qa > qb
|
|
case d <= -25:
|
|
return qa < qb
|
|
}
|
|
return true
|
|
}
|
|
return !(pair(src.R, src.G, q.R, q.G) && pair(src.G, src.B, q.G, q.B) && pair(src.R, src.B, q.R, q.B))
|
|
}
|
|
|
|
type stat struct{ lost, flip, seen int }
|
|
byHour := map[float64]*stat{}
|
|
var hours []float64
|
|
totalLost, totalFlip, totalGlyphs := 0, 0, 0
|
|
|
|
for i := 0; i < 24; i++ {
|
|
tod := float64(i) / 24
|
|
c := canvas.New(w, h, canvas.AlphaFar, canvas.AlphaMid, canvas.AlphaNear)
|
|
sh := scape.NewShore(7, false)
|
|
cat := companion.NewCat()
|
|
cat.FaceLeft(true)
|
|
ccw, chh := cat.Size()
|
|
lay := compose(w, ccw, true)
|
|
sh.MoonX = lay.MoonX
|
|
for k := 0; k < 12; k++ {
|
|
sh.Update(c, 3.0+float64(k)/20, scape.Activity{
|
|
Working: true, Level: 0.6, TimeOfDay: tod, ContextUsed: 0.3})
|
|
}
|
|
drawScene(c, sh, cat, lay,
|
|
reduce.State{Pose: companion.Working, Tail: tail}, 3.7, 7, c.H-2-chh)
|
|
|
|
st := &stat{}
|
|
byHour[tod] = st
|
|
hours = append(hours, tod)
|
|
for y := 0; y < h; y++ {
|
|
for x := 0; x < w; x++ {
|
|
ch, src, _ := c.ResolveAt(x, y, term.ProfileTrueColor)
|
|
if ch == ' ' {
|
|
continue // no glyph: that is the background audit's business
|
|
}
|
|
_, painted, _ := c.ResolveAt(x, y, term.Profile256)
|
|
st.seen++
|
|
totalGlyphs++
|
|
// Three outcomes, and the first version of this probe ran the
|
|
// first two together: a glyph that goes grey has no channel
|
|
// ordering left to reverse, so it was being counted as a hue
|
|
// flip as well and the flip column read four times too high.
|
|
// Washed out and wrong-coloured are different defects with
|
|
// different fixes.
|
|
switch {
|
|
case chromaOf(src) >= 40 && chromaOf(painted) < 20:
|
|
st.lost++
|
|
totalLost++
|
|
case chromaOf(painted) >= 20 && flipped(src, painted):
|
|
st.flip++
|
|
totalFlip++
|
|
}
|
|
}
|
|
}
|
|
}
|
|
sort.Float64s(hours)
|
|
fmt.Printf("%-7s %8s %16s %18s\n", "hour", "glyphs", "washed to grey", "wrong hue, coloured")
|
|
for _, tod := range hours {
|
|
s := byHour[tod]
|
|
fmt.Printf("%02d:00 %8d %8d %4.1f%% %8d %4.1f%%\n", int(tod*24), s.seen,
|
|
s.lost, 100*float64(s.lost)/float64(s.seen),
|
|
s.flip, 100*float64(s.flip)/float64(s.seen))
|
|
}
|
|
fmt.Printf("\nTOTAL %8d %8d %4.1f%% %8d %4.1f%%\n", totalGlyphs,
|
|
totalLost, 100*float64(totalLost)/float64(totalGlyphs),
|
|
totalFlip, 100*float64(totalFlip)/float64(totalGlyphs))
|
|
}
|