Files
JoshHeaps.Net/tests/holdem/seatFootprint.test.js
jheapsandClaude Opus 5 f93e0935ef Give every seat its own pixels
Six players at a nine-handed table is the most ordinary table this tool draws, and on
every phone in the sweep one of them had their stack painted under the player next to
them. Measured across nine viewports and six table sizes: seventeen of fifty-four
tables hid a name or a stack behind something belonging to another seat.

Two causes, and the layout only knew about a third of one of them.

The felt decided how big a puck could be from a single number — the straight-line
distance between the closest two *neighbouring* seats, judged against a fraction of a
puck's width. Distance has one number in it and a puck is half again as wide as it is
tall, so the same 84px was generous side by side and nowhere near enough on the
diagonal. And neighbours are the wrong pairs to ask about: on a phone held sideways the
felt is 528x87, the ring is very nearly a straight line, and the seat that lands on top
of you is the one across the table. Ten of the tables in the sweep had a collision that
a neighbours-only check cannot see — seats 1 and 7, overlapping by 68px, while every
adjacent pair had room.

seatsCollide() asks the real question instead: do any two of these boxes want the same
pixels. Two equal axis-aligned boxes overlap exactly when their centres are closer than
one box in both axes, so it is an answer rather than a proxy, and it looks at every
pair.

The second cause was the small blind badge, sitting at `left: -6px` — hanging off its
own puck's left corner onto whatever was beside it. On an iPhone Pro Max at six seats,
with the pucks not touching at all, "SB" was painted across the next player's $1,137.
All three badges now sit inside the puck's width, and in the same place as each other:
a seat only ever wears one, so two positions bought nothing except making the dealer's
eye find which of two spots this seat was using before it could read which blind it is.

Then the layout had to be able to act on the answer, and it couldn't. It chose between
two widths — 96px or 58px — and if neither fitted it widened the ring and let the seats
overlap, on the reasoning that a dealer can see an overhang but cannot see a tap landing
on the wrong player. That trade is real; it was also a false choice, because the tables
that overlapped did not want either number. At nine seats a Galaxy S8 had room for a
61px puck, an iPhone 14 for 68, a Pixel 7 for 74, an iPhone Pro Max for 79. Three media
queries declared three more of these numbers — 78px, 64px, 62px — at three breakpoints,
guessing at something a media query cannot see: the same 390px phone has room for a 90px
puck at four seats and 61 at nine.

So the width is searched for now, not chosen. render.js walks candidates from the top,
applies each one, measures what the browser actually drew, and takes the widest that
leaves every seat its own box. There was a width that worked on every table in the
sweep; the code was never asking for it. Ten candidates is ten forced layouts, so the
result is cached against the felt's size, the seat count and the names — measured 12.5ms
cold, 0.8ms warm, and renderSeats runs after every tap.

Three things this got wrong on the way, all caught by measuring rather than reading:

  The badge overhang was folded into the space between two seats. That collapsed the
  ring on a phone held sideways — 87px of height, and 18px of badge is most of the room
  the ring has to move in — until a six-handed landscape table was unsatisfiable at any
  width. It didn't belong there: the badge points *away* from the table at both ends, so
  two seats facing each other across the felt wear them back to back.

  box-sizing: border-box, which the puck needed so the searched number means the width
  it is drawn at, quietly turned every min-height from a content height into a drawn one.
  An empty chair went from a 52px tap target to a 42px one on every phone in the sweep.
  The audit found it; the four min-heights have each gained the padding and border they
  used to be quoted without.

  The new audit check reported a name under a neighbour on a table whose seats were 9px
  apart. A puck's name is a `-webkit-box` with `line-clamp`, and getClientRects() hands
  back a rect for every line the text *would* have taken, including the ones the clamp
  throws away — so the probe was hit-testing 30px below the puck, where nothing is
  painted. It clips to what is painted now.

uiAudit gains "no seat covers another seat's writing", the complement of the check
already there for a puck's own decoration on its own name — which is why nothing caught
this: seatLabelsClear() only ever looked inside one seat. Fault-injected against the
previous version: eighteen configurations, naming both causes.

And the sweep itself now runs two table shapes. It had run one for its whole life —
five players at a nine-handed table — and how crowded the felt is depends on how many
people are sitting down far more than on anything a viewport can report. A full table
was never once looked at.

632 tests, 0 failures. 190 audits across thirteen viewports at two table shapes, with a
mouse and with a thumb. Every table from two seats to twelve now keeps its own text on
every viewport in the sweep. One configuration still reports: a dozen players on a
640x360 phone, where the felt is 87px tall and two rows of 55px pucks cannot both fit
and stay on the rail — the ring grows 8px past the edge to keep the seats off each
other, which is the trade the old code named and got right. Left reported rather than
tuned away.

Names on a crowded phone table truncate harder than they did, because the puck is now
sized to fit instead of allowed to overlap: "Christopher" is "Christ…" at nine seats on
an iPhone 14. The full name is in the DOM, in the seat's form and in the sidebar. The
next lever on that is the seat layer's inset, which is still a fixed 44px of "half a
puck" for a puck that is no longer 96px wide — worth 54px to 60px where it was measured.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015bnp7xKUPFFSpwkYNFaPgb
2026-09-03 13:23:31 -06:00

175 lines
9.0 KiB
JavaScript

// Whether two seats can end up wanting the same pixels.
//
// The felt used to decide this from one number: the straight-line distance between the
// closest two *neighbouring* seats, judged against a fraction of a puck's width. Both
// halves of that were wrong, and the running page showed it. Measured across nine
// viewports and six table sizes:
//
// seventeen of fifty-four tables had one seat's name or stack painted under another
// ten of them had the collision between two seats that are not neighbours
//
// The second number is the interesting one. On a phone held sideways the felt is 528px
// wide and 87 tall, the ring is very nearly a straight line, and the seat that lands on
// top of you is the one across the table — seats 1 and 7, overlapping by 68px, while
// every neighbouring pair was fine and the check said the table was clean.
//
// The first is what a distance test can't fix even looking at every pair: distance has
// one number in it, and a puck is half again as wide as it is tall. 84px between centres
// is generous side by side and nowhere near enough on the diagonal.
const test = require("node:test");
const { describe } = require("node:test");
const assert = require("node:assert");
const fs = require("fs");
const path = require("path");
const { Render } = require("./load");
const CSS = fs.readFileSync(
path.join(__dirname, "..", "..", "JoshHeaps.Net", "wwwroot", "css", "casino", "holdem.css"), "utf8");
describe("two boxes on a ring", () => {
// A phone held sideways, once the action bar has taken its share: a felt far wider
// than it is tall, on which the ring is very nearly a straight line.
const felt = { width: 400, height: 70 };
const flat = { rx: 44, ry: 42 };
test("a pair that is not neighbours still counts", () => {
// Eight seats, a 48x60 puck. Every neighbouring pair is clear. Seats 1 and 5 are
// on top of each other, and so are 2 and 4, and 6 and 8 — the seat that lands on
// you here is the one across the table, because the rim doubles back at the ends
// of a shape this flat and a long walk apart is no distance at all.
assert.equal(Render.seatsCollide(8, felt, flat, 48, 60), true);
const neighbours = (count, w, h) => {
const points = Render.ringPositions(count, flat.rx, flat.ry, felt.width / felt.height)
.map(s => ({ x: (s.left / 100) * felt.width, y: (s.top / 100) * felt.height }));
return points.some((point, i) => {
const next = points[(i + 1) % points.length];
return Math.abs(point.x - next.x) < w && Math.abs(point.y - next.y) < h;
});
};
assert.equal(neighbours(8, 48 + Render.SEAT_CLEARANCE_PX, 60 + Render.SEAT_CLEARANCE_PX), false,
"no neighbouring pair overlaps, which is exactly why this had to look at all of them");
});
test("and the answer is the box, not a radius", () => {
// Two seats 60px apart across and 35px down, with a 64x40 puck. The distance
// between them is 69px, so the test this replaces — "are these two further apart
// than a puck is wide?" — called it clear. The boxes overlap by 4px by 5px.
const boxes = { width: 200, height: 100 };
const twoSeats = (dx, dy) => {
const original = Render.ringPositions;
Render.ringPositions = () => [
{ left: 50 - (dx / 2 / boxes.width) * 100, top: 50 - (dy / 2 / boxes.height) * 100 },
{ left: 50 + (dx / 2 / boxes.width) * 100, top: 50 + (dy / 2 / boxes.height) * 100 },
];
try {
return Render.seatsCollide(2, boxes, flat, 64, 40, 0);
} finally {
Render.ringPositions = original;
}
};
assert.ok(Math.hypot(60, 35) > 64, "and a distance test would have passed it");
assert.equal(twoSeats(60, 35), true, "60 across and 35 down, with a 64x40 puck");
assert.equal(twoSeats(60, 45), false, "far enough apart vertically");
assert.equal(twoSeats(66, 10), false, "far enough apart horizontally");
});
test("with daylight, so rounded corners don't read as touching", () => {
assert.ok(Render.SEAT_CLEARANCE_PX > 0);
});
test("a table nobody is sitting at can't collide with itself", () => {
assert.equal(Render.seatsCollide(1, felt, flat, 96, 60), false);
assert.equal(Render.seatsCollide(9, null, flat, 96, 60), false);
});
});
describe("the widths the felt may choose from", () => {
test("run widest first, because the widest that fits is the one wanted", () => {
const widths = Render.seatWidthCandidates();
widths.slice(1).forEach((w, i) => assert.ok(w < widths[i], `${widths[i]} then ${w}`));
});
test("and span the whole declared range", () => {
const widths = Render.seatWidthCandidates();
assert.equal(widths[0], Render.SEAT_WIDTH_MAX);
assert.equal(widths[widths.length - 1], Render.SEAT_WIDTH_MIN);
});
test("the floor is still a name, not a smudge", () => {
// At 44px the tight layout shows about five characters and an ellipsis. Below
// that a puck stops telling the dealer who is sitting there, which is the one
// thing on the felt it exists to say.
assert.ok(Render.SEAT_WIDTH_MIN >= 44);
assert.ok(Render.SEAT_TIGHT_BELOW_PX > Render.SEAT_WIDTH_MIN);
assert.ok(Render.SEAT_TIGHT_BELOW_PX < Render.SEAT_WIDTH_MAX);
});
test("and there are few enough of them to measure after every tap", () => {
// Each one costs a forced layout. Ten is the budget; the cache carries the rest.
assert.ok(Render.seatWidthCandidates().length <= 12);
});
});
describe("what the stylesheet has to keep holding up", () => {
test("the puck's width comes from the property, not from a breakpoint", () => {
// Three media queries used to declare it — 78px, 64px and 62px — three guesses
// at a number that depends on how many people are sitting down, which no media
// query can see. The same 390px phone has room for 90px at four seats and 61 at
// nine.
const declarations = CSS.replace(/\/\*[\s\S]*?\*\//g, "");
const seatRules = [...declarations.matchAll(/(^|[,}])\s*(\.seat)\s*\{([^}]*)\}/g)]
.map(m => m[3]);
const hardWidths = seatRules
.flatMap(body => body.match(/(?<![\w-])width:\s*[^;]+/g) || [])
.filter(decl => !decl.includes("var(--seatPuckW"));
assert.deepEqual(hardWidths, []);
});
test("the puck measures what it says it measures", () => {
// As content-box a 64px puck came out 74 across once its padding and border were
// counted, and the search compares that number against distances on the felt.
const rule = CSS.match(/\n\.seat \{[^}]*\}/);
assert.ok(rule, ".seat rule not found");
assert.match(rule[0], /box-sizing:\s*border-box/);
});
test("and a blind badge never reaches sideways off its own puck", () => {
// This is what makes the footprint the puck and nothing more. The badge's
// remaining overhang is vertical, and it points away from the table at both ends
// — `top` on the upper arc, `bottom` on the lower — so two seats facing each
// other across the felt wear their badges back to back.
//
// It was not always so: at `left: -6px` the small blind hung off the puck's left
// corner, and on an iPhone Pro Max at six seats — pucks not touching at all —
// "SB" was painted across the next player's $1,137.
const badges = [...CSS.matchAll(/\.(sb|bb|str)Badge\s*\{([^}]*)\}/g)];
assert.equal(badges.length, 3, "expected all three blind badges");
badges.forEach(([, which, body]) => {
const left = body.match(/(?<![\w-])left:\s*(-?[\d.]+)px/);
assert.ok(left, `.${which}Badge should place itself horizontally`);
assert.ok(Number(left[1]) >= 0,
`.${which}Badge sits at ${left[1]}px, off the left of its own puck`);
});
});
test("and all three sit in the same place, so there is one spot to look at", () => {
// Two badges in two positions means the dealer's eye has to find which of them
// this seat is using before it can read which blind it is, forty times a night.
// A seat only ever wears one: the blinds are different players by construction,
// and the straddle chain starts left of the big blind and stops short of the
// small one.
const lefts = [...CSS.matchAll(/\.(sb|bb|str)Badge\s*\{([^}]*)\}/g)]
.map(([, , body]) => (body.match(/(?<![\w-])left:\s*(-?[\d.]+px)/) || [])[1]);
assert.equal(new Set(lefts).size, 1, `badges sit at ${lefts.join(", ")}`);
});
});
describe("with no browser to measure", () => {
test("nothing here throws", () => {
assert.equal(Render.measuredSeatBox(), null);
assert.equal(Render.seatFootprint(null), null);
assert.deepEqual(Render.seatFootprint({ width: 64, height: 40 }), { width: 64, height: 40 });
});
});