scene: ES2016-safe hasOwnProperty, tighten undefined-bucket assertion, reflow bound comment
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
fff46492ca
commit
5eb0a63caa
3 changed files with 6 additions and 6 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import { describe, expect, it } from 'vitest';
|
import { describe, expect, it } from 'vitest';
|
||||||
import { BUCKET_SCALE, creatureScale, NEUTRAL_SCALE, SizeBucket } from './creatures';
|
import { BUCKET_SCALE, creatureScale, SizeBucket } from './creatures';
|
||||||
|
|
||||||
const buckets: SizeBucket[] = ['small', 'medium', 'large'];
|
const buckets: SizeBucket[] = ['small', 'medium', 'large'];
|
||||||
|
|
||||||
|
|
@ -17,7 +17,7 @@ describe('creature scale', () => {
|
||||||
|
|
||||||
it('does not crash or default to medium when a non-neutral creature has no sizeBucket', () => {
|
it('does not crash or default to medium when a non-neutral creature has no sizeBucket', () => {
|
||||||
expect(creatureScale({ neutral: false })).toBeNull();
|
expect(creatureScale({ neutral: false })).toBeNull();
|
||||||
expect(creatureScale({ sizeBucket: undefined, neutral: false })).not.toBe(BUCKET_SCALE.medium);
|
expect(creatureScale({ sizeBucket: undefined, neutral: false })).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('draws nothing for an unknown bucket, including inherited property names', () => {
|
it('draws nothing for an unknown bucket, including inherited property names', () => {
|
||||||
|
|
|
||||||
|
|
@ -33,5 +33,5 @@ export const BUCKET_SCALE: Readonly<Record<SizeBucket, number>> = {
|
||||||
/** The draw scale, or null when nothing is drawn: a neutral creature, or a bucket that is absent or unknown. */
|
/** The draw scale, or null when nothing is drawn: a neutral creature, or a bucket that is absent or unknown. */
|
||||||
export function creatureScale(c: Pick<Creature, 'sizeBucket' | 'neutral'>): number | null {
|
export function creatureScale(c: Pick<Creature, 'sizeBucket' | 'neutral'>): number | null {
|
||||||
if (c.neutral || c.sizeBucket === undefined) return null;
|
if (c.neutral || c.sizeBucket === undefined) return null;
|
||||||
return Object.hasOwn(BUCKET_SCALE, c.sizeBucket) ? BUCKET_SCALE[c.sizeBucket] : null;
|
return Object.prototype.hasOwnProperty.call(BUCKET_SCALE, c.sizeBucket) ? BUCKET_SCALE[c.sizeBucket] : null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,9 @@ export const WORLD = {
|
||||||
erodeNorm: 0.5,
|
erodeNorm: 0.5,
|
||||||
// Bound on |grad| of the phasor's cos component for the side and norm above. Libby measured a
|
// Bound on |grad| of the phasor's cos component for the side and norm above. Libby measured a
|
||||||
// sup of 6.63 at |side| = 1.5, n = 0 (CultLib PR #1 head 990521b3); 7.0 adds margin.
|
// sup of 6.63 at |side| = 1.5, n = 0 (CultLib PR #1 head 990521b3); 7.0 adds margin.
|
||||||
// The sup was measured, not proved. The
|
// The sup was measured, not proved. The shader passes roughness n = 0 as a literal, so the doc
|
||||||
// shader passes roughness n = 0 as a literal, so the doc envelope max(10, 1.25|side|)/(1-n)
|
// envelope max(10, 1.25|side|)/(1-n) needs no 1/(1-n) factor here; if n ever becomes nonzero,
|
||||||
// needs no 1/(1-n) factor here; if n ever becomes nonzero, divide this bound by (1 - n).
|
// divide this bound by (1 - n).
|
||||||
// |value| <= 1 holds by construction (the output is a normalized phasor).
|
// |value| <= 1 holds by construction (the output is a normalized phasor).
|
||||||
// Typed number, not the literal 7, so callers can build variants such as { ...WORLD, phacelleGradBound: 0 }.
|
// Typed number, not the literal 7, so callers can build variants such as { ...WORLD, phacelleGradBound: 0 }.
|
||||||
phacelleGradBound: 7.0 as number,
|
phacelleGradBound: 7.0 as number,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue