fix: polish pass for traffic, nav, icons, contact email reveal and dashcam robustness
This commit is contained in:
@@ -1,23 +1,53 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
HERO_CAR_HALF_WIDTH,
|
||||
TRAFFIC_BODY,
|
||||
TRAFFIC_FADE_LENGTH,
|
||||
TRAFFIC_LAMP_HALF_SPACING,
|
||||
TRAFFIC_LANE_JITTER,
|
||||
TRAFFIC_LANES,
|
||||
TRAFFIC_NEAR_Z,
|
||||
trafficLamps,
|
||||
trafficNearFade,
|
||||
wrapTrafficZ,
|
||||
} from '@/scene/world/traffic';
|
||||
|
||||
describe('expressway traffic stays clear of the hero car', () => {
|
||||
it('keeps every lamp outside the car body, with lane jitter', () => {
|
||||
it('keeps every body outside the hero car, with lane jitter', () => {
|
||||
for (const lane of TRAFFIC_LANES) {
|
||||
const half = lane < 0 ? TRAFFIC_LAMP_HALF_SPACING.fast : TRAFFIC_LAMP_HALF_SPACING.slow;
|
||||
const innerLamp = Math.abs(lane) - half - 0.25; // 0.25: max lane jitter
|
||||
expect(innerLamp).toBeGreaterThan(HERO_CAR_HALF_WIDTH);
|
||||
const inner = Math.abs(lane.x) - TRAFFIC_BODY[lane.kind].halfWidth - TRAFFIC_LANE_JITTER;
|
||||
expect(inner).toBeGreaterThan(HERO_CAR_HALF_WIDTH);
|
||||
}
|
||||
});
|
||||
|
||||
it('never lets bodies in adjacent lanes overlap, and keeps them on the road', () => {
|
||||
const spans = TRAFFIC_LANES.map((lane) => {
|
||||
const half = TRAFFIC_BODY[lane.kind].halfWidth + TRAFFIC_LANE_JITTER;
|
||||
return [lane.x - half, lane.x + half] as const;
|
||||
}).sort((a, b) => a[0] - b[0]);
|
||||
for (let i = 1; i < spans.length; i++) expect(spans[i]![0]).toBeGreaterThan(spans[i - 1]![1]);
|
||||
for (const [left, right] of spans) {
|
||||
expect(left).toBeGreaterThan(-8);
|
||||
expect(right).toBeLessThan(8);
|
||||
}
|
||||
});
|
||||
|
||||
it('runs each lane at one speed, so no vehicle drives through another', () => {
|
||||
const xs = TRAFFIC_LANES.map((lane) => lane.x);
|
||||
expect(new Set(xs).size).toBe(xs.length);
|
||||
});
|
||||
|
||||
it('puts every lamp on the vehicle body', () => {
|
||||
for (const kind of ['car', 'truck'] as const) {
|
||||
const lamps = trafficLamps(kind, 0.5);
|
||||
expect(lamps.length).toBeGreaterThanOrEqual(3);
|
||||
for (const lamp of lamps) expect(Math.abs(lamp.x) + lamp.w / 2).toBeLessThanOrEqual(TRAFFIC_BODY[kind].halfWidth + 0.01);
|
||||
}
|
||||
// A readable pair: two tail lamps mirrored at one height.
|
||||
const [left, right] = trafficLamps('car', 0);
|
||||
expect(left!.x).toBe(-right!.x);
|
||||
expect(left!.y).toBe(right!.y);
|
||||
});
|
||||
|
||||
it('is fully dark before the car near field and lit beyond the fade', () => {
|
||||
expect(trafficNearFade(TRAFFIC_NEAR_Z)).toBe(0);
|
||||
expect(trafficNearFade(0)).toBe(0);
|
||||
|
||||
Reference in New Issue
Block a user