scene: keep the terrain sky and baked tables out of the main chunk
Some checks failed
Build pull request / Build pull request (pull_request) Has been cancelled
Some checks failed
Build pull request / Build pull request (pull_request) Has been cancelled
skyBackdrop reads constants (the union of the ridge and terrain skies, rounded outward) instead of computing it, and the door imports skyForState lazily with the scenes. A test fails when the constants drift from the computed union. Main entry chunk vs dev: +0.4 KB gzip, down from +51.5 KB. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
edc6a9a8f1
commit
0d26b71862
3 changed files with 46 additions and 25 deletions
|
|
@ -116,3 +116,36 @@ describe('both scenes of a state lie inside skyBackdrop', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('skyBackdrop holds the union of what the scenes draw', () => {
|
||||
const computed = (state: 'day' | 'dusk' | 'night') => {
|
||||
const r = [ridgeDrawn(state), terrainDrawn(state)].filter((x) => x !== undefined) as {
|
||||
darkest: number;
|
||||
lightest: number;
|
||||
}[];
|
||||
return {
|
||||
darkest: Math.min(...r.map((x) => x.darkest)),
|
||||
lightest: Math.max(...r.map((x) => x.lightest)),
|
||||
};
|
||||
};
|
||||
|
||||
it.each(['day', 'dusk', 'night'] as const)(
|
||||
'%s: the constant bounds the computed range and sits within 1e-5 of it',
|
||||
(state) => {
|
||||
const c = computed(state);
|
||||
const b = skyBackdrop(state);
|
||||
expect(b.darkest).toBeLessThanOrEqual(c.darkest);
|
||||
expect(b.lightest).toBeGreaterThanOrEqual(c.lightest);
|
||||
expect(c.darkest - b.darkest).toBeLessThan(1e-5);
|
||||
expect(b.lightest - c.lightest).toBeLessThan(1e-5);
|
||||
}
|
||||
);
|
||||
|
||||
it('auto is the union of the three fixed states', () => {
|
||||
const all = (['day', 'dusk', 'night'] as const).map(skyBackdrop);
|
||||
expect(skyBackdrop('auto')).toEqual({
|
||||
darkest: Math.min(...all.map((x) => x.darkest)),
|
||||
lightest: Math.max(...all.map((x) => x.lightest)),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue