Files
donlucasandClaude Opus 5 7b2fdd711c The disc's caps stop drawing seventy pixels of line for no roundness
The fix the last session proposed was wrong, and it was U+2580 in disguise.
"Pick the half-block ORIENTATION per cell, so every gap is painted in the
colour it sits against" cannot work: Menlo's block ink runs 4.6 to 29.4 of a
30px row, so a cell has exactly two achievable partitions and BOTH leave the
background showing.

    U+2584  up[0,17] down[17,29.4] UP[29.4,30]   -- 0.6px wrong at the bottom
    U+2580  DOWN[0,4.6] up[4.6,17] down[17,30]   -- 4.6px wrong at the top

Making the sliver match what is below forces bg = the lower colour, which
means U+2580 everywhere -- the glyph term.LowerHalf exists to avoid. There is
no third glyph either: every block element shares that ink box, so the bottom
0.6px of any cell that draws one is its background. The leak is the terminal,
not the renderer.

What is actually wrong is the RUN, not the pixel. notes/rulecount rasterises
a frame at Terminal.app's geometry and counts rules AND their widths. His own
crop calibrates it: at the disc's centre column, 17px of sky (50,95,131), 12px
of rim (165,137,136), ONE px of (100,113,134) -- and 0.43*rim + 0.57*sky is
(96,112,133), within two counts on every channel. So inkBot 29.4 and an alpha
of 0.43 are measured off his screen, not assumed.

At his own 128x27 the whole frame carries four rules and all four are on the
disc: two FIVE cells wide at the flat top and bottom caps, two one cell wide
at the shoulders. A split cell whose neighbour's edge falls in the same cell
on the same side is on a horizontal stretch of the silhouette -- it buys no
roundness at all, and the only thing it draws is seventy pixels of rule.

Shore.FlatCaps gives those cells a whole cell and leaves the sloped ones
split, which is where the curve lives. Over 6 widths x 7 heights x 48
half-hours: longest rule run 5 cells -> 1, rule cells 12920 -> 4922. The
silhouette's width profile is IDENTICAL; only the cap's fill goes from half a
row to a whole one. Gated on term.NoSplitCells, so Ghostty keeps the full
half-row edge everywhere.

Two things about the tests. TestTheMoonIsRoundAtEveryHeight was running at
this suite's zero values, which are GHOSTTY'S -- NoSplitCells false, the very
switch the collapse is gated on -- so it was clearing a disc nobody ships. It
now runs both flag states. And TestNoRuleRunsAcrossTheDiscsCap was checked to
FAIL with FlatCaps off (60x16, two cells of rule side by side) before being
trusted, because a test that passes either way proves nothing.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015GQLYhGnSpasru9xeJbJry
2026-09-07 21:10:15 -07:00

151 lines
5.9 KiB
Go

package scape
import (
"math"
"testing"
"github.com/donlucasx/xscapes/internal/canvas"
"github.com/donlucasx/xscapes/internal/term"
)
// No cell in the middle of the disc is drawn as a half block.
//
// A half block on Terminal.app leaves a one-pixel rule at the cell's bottom
// edge: its ink runs to 29.4 of a 30px row and the last device pixel row falls
// back to the cell's background, which is the other half's colour. At the disc's
// EDGE that is the silhouette and it is what keeps the disc round. In the
// INTERIOR it is a rule straight across the face, and he reported it three
// times -- measured off his own screen 2026-09-07 at the disc's centre column:
// twelve pixels of one tone, one pixel of a blend, then sixty more of the tone.
//
// A cell whose neighbours above and below are also disc is an interior cell, so
// if it is a half block the rule has come back.
func TestNoRuleRunsAcrossTheDiscsFace(t *testing.T) {
prev := term.NoSplitCells
prevHalf := term.LowerHalf
term.NoSplitCells, term.LowerHalf = true, true
defer func() { term.NoSplitCells, term.LowerHalf = prev, prevHalf }()
for _, w := range []int{60, 80, 100, 126, 152} {
for _, h := range []int{16, 20, 24, 28, 34, 40, 47} {
// FULL PHASE, and the reason is exactness rather than convenience.
// By day the sun wanes as a crescent and moon() SKIPS a half-row
// falling inside the terminator, so a cell can be geometrically
// inside the disc with only ONE half painted -- a true silhouette
// edge, which must keep its split. At full phase the terminator is
// clear of the face entirely, so "geometrically inside" and
// "painted" are the same thing and the check below is exact at
// every hour.
for i := 0; i < 24; i++ {
tod := float64(i) / 24
c := canvas.New(w, h, canvas.AlphaFar, canvas.AlphaMid, canvas.AlphaNear)
sh := NewShore(7, false)
sh.MoonX = 0.28
sh.Update(c, 3, Activity{Working: true, Level: 0.5, TimeOfDay: tod, ContextUsed: 0})
if !sh.moonPainted || sh.moonRR <= 0 {
continue
}
// BOTH of a cell's own half-rows inside the disc is the real
// invariant -- the same test moon() paints by. DiscCovers is
// true when EITHER half is inside, so using it here would call
// the disc's own edge ring "interior" and demand it stop
// splitting, which is exactly what keeps the disc round.
bothHalvesIn := func(x, y int) bool {
fx := float64(x-sh.moonX) / 2.0
for _, off := range [2]float64{-0.25, 0.25} {
if math.Hypot(fx, float64(y-sh.moonY)+off) >= sh.moonRR {
return false
}
}
return true
}
for y := 1; y < h-1; y++ {
for x := 0; x < w; x++ {
if !bothHalvesIn(x, y) {
continue
}
r, _, _ := c.ResolveAt(x, y, term.Profile256)
if r == '▄' || r == '▀' {
t.Fatalf("%dx%d tod=%.2f: cell (%d,%d) has BOTH halves inside the disc and is drawn as %q -- "+
"that is a one-pixel rule across the face", w, h, tod, x, y, string(r))
}
}
}
}
}
}
}
// No rule on the disc runs more than one cell wide.
//
// A split cell on Terminal.app always leaks about one device pixel of its
// background at the cell's bottom edge; that is the terminal, not us, and no
// glyph avoids it (the full block's ink runs 4.6..29.4 of a 30px row, so the
// last row is the background whatever is drawn). What turns that pixel into
// something he can see is the RUN -- neighbouring columns putting their sliver
// on the same device row, which is what the disc's flat top and bottom caps
// did: five cells, seventy pixels, straight across the sun. Measured in his
// 8.27.52 PM crop of 2026-09-07: 17px of sky, 12px of rim, then one pixel of
// (100,113,134), which is 0.43*rim + 0.57*sky.
//
// A one-cell rule is the silhouette's own texture at a shoulder and reads as
// an edge. Anything longer is a line. Shore.FlatCaps collapses exactly the
// cells that cannot buy roundness -- those whose neighbour's edge falls in the
// same cell on the same side -- and leaves the curve alone.
func TestNoRuleRunsAcrossTheDiscsCap(t *testing.T) {
prev, prevHalf := term.NoSplitCells, term.LowerHalf
term.NoSplitCells, term.LowerHalf = true, true
defer func() { term.NoSplitCells, term.LowerHalf = prev, prevHalf }()
// The sliver is 0.43 ink over 0.57 background, measured off his screen.
sliver := func(fg, bg term.RGB) term.RGB {
m := func(a, b uint8) uint8 { return uint8(0.43*float64(a) + 0.57*float64(b) + 0.5) }
return term.RGB{R: m(fg.R, bg.R), G: m(fg.G, bg.G), B: m(fg.B, bg.B)}
}
far := func(a, b term.RGB) float64 {
dr, dg, db := float64(a.R)-float64(b.R), float64(a.G)-float64(b.G), float64(a.B)-float64(b.B)
return math.Sqrt(dr*dr + dg*dg + db*db)
}
for _, w := range []int{60, 80, 100, 128, 143, 152} {
for _, h := range []int{16, 20, 24, 27, 34, 40, 47} {
for i := 0; i < 48; i++ {
c := canvas.New(w, h, canvas.AlphaFar, canvas.AlphaMid, canvas.AlphaNear)
sh := NewShore(7, false)
sh.MoonX = 0.28
sh.Update(c, 3, Activity{Working: true, Level: 0.5, TimeOfDay: float64(i) / 48, ContextUsed: 0})
if !sh.moonPainted || sh.moonRR <= 0 {
continue
}
// A cell rules when its sliver differs from the ink directly
// above it AND from the cell below. Where the cell below
// carries the background's own colour the sliver lands in its
// own colour and nothing shows.
rules := func(x, y int) bool {
ch, fg, bg := c.ResolveAt(x, y, term.Profile256)
if ch != '▄' {
return false
}
sl := sliver(fg, bg)
_, _, below := c.ResolveAt(x, y+1, term.Profile256)
return far(sl, fg) >= 6 && far(sl, below) >= 6
}
for y := 1; y < h-1; y++ {
run := 0
for x := 0; x < w; x++ {
if !rules(x, y) {
run = 0
continue
}
run++
if run > 1 {
t.Fatalf("%dx%d tod=%.2f: %d cells of rule side by side ending at (%d,%d) -- "+
"that is a line across the disc, not an edge", w, h, float64(i)/48, run, x, y)
}
}
}
}
}
}
}